javascript - Assign variable set in one function to a variable in another function -


i'm trying assign variable strsel in function outputselected variable testvar in function testresults. what's best way achieve this?

function getselected(opt) {     var selected = new array();     var index = 0;     (var intloop = 0; intloop < opt.length; intloop++) {         if ((opt[intloop].selected) || (opt[intloop].checked)) {             index = selected.length;             selected[index] = new object;             selected[index].value = opt[intloop].value;             selected[index].index = intloop;         }     }      return selected; }  function outputselected(opt) {     var sel = getselected(opt);     var strsel = "";     (var item in sel)            strsel += sel[item].value + ",";     window.document.title = strsel; }  function testresults (form) {     var testvar = // want pass strsel here. window.document.title=(testvar); } 

just use global variable :-

then set variable in 1 function , can use variable value in function.

var myvar;// declare global variable  function outputselected(opt) {         var sel = getselected(opt);         var strsel = "";         (var item in sel)                   strsel += sel[item].value + ",";         // set var:-          myvar=strsel ;          window.document.title=(strsel);  <----- result             }      function testresults (form) {          var testvar= myvar;         //alert (testvar + "\n" + testvar1 + "\n" + testvar2 + "\n" + testvar3 + "\n" + testvar4 + "\n" + testvar5);         window.document.title=(testvar);     } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -