Automatically pass the retrieved value from a javascript function to another javascript function?
<p>I have two inline java script functions, one intended to get a token value using xhr and second one will use that value to get the full response from server. But when i uploaded the same on server nothing happened. </p>

<p>Here goes the sample code:</p>

<pre><code>function getUser(user)
      {


   var xmlhttp;
   var result,x,i;
   var uservalue=user;
   var url="http://abc.xyz.com:8090/uauth/" +uservalue;
   ///here starts the getToken method..
   var tokensave=function getToken(uservalue)
                    {
                     var xmlhttp;
                     var token,a,b;
                     var url="http://abc.xyz.com:8090/uauth/" +uservalue;
                     var data="op=login&amp;pass=" +uservalue;   


                     if (window.XMLHttpRequest)
                        {// code for IE7+, Firefox, Chrome, Opera, Safari
                         xmlhttp=new XMLHttpRequest();

                                 if (xmlhttp==null)
                                    {
                                     alert ("Browser does not support HTTP Request");
                                     return;
                                     }

                         }
                    else
                         {// code for IE6, IE5

                          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                         }

                    xmlhttp.open("POST",url, true);

                    xmlhttp.onreadystatechange=function()
                         {

                                if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
                                   {

                                    xmlDoc=xmlhttp.responseXML;
                                    token="";
                                    a=xmlDoc.getElementsByTagName("token");

                                    token=token + a.childNodes.nodeValue;

                                        document.getElementById("myDiv").innerHTML=token;
                                    }
                          };

                     xmlhttp.setRequestHeader("Content-Type", "text/xml");   
                     xmlhttp.send(data);
                     return token;

                 }


   var header="Xyz-Authorization: "+tokensave;


                     if (window.XMLHttpRequest)
                        {// code for IE7+, Firefox, Chrome, Opera, Safari
                         xmlhttp=new XMLHttpRequest();

                     if (xmlhttp==null)
                        {
                        alert ("Browser does not support HTTP Request");
                        return;
                        }

                        }
                     else
                        {// code for IE6, IE5
                         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                        }

                         xmlhttp.open("GET",url, true);

   xmlhttp.onreadystatechange=function()
                        {
                            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
                               {

                               xmlDoc=xmlhttp.responseXML;
                               result="";
                               x=xmlDoc.getElementsByTagName("response");
                               for (i=0;i&lt;x.length;i++)
                                    {
                                     result=result + x[i].childNodes[0].nodeValue + "&lt;br /&gt;";
                                    }
                               document.getElementById("myNewDiv").innerHTML=result;
                               }
                         };

   xmlhttp.setRequestHeader("Xyz-Authorization: ", +tokensave);
   xmlhttp.send();


 }
   HTML CODE:
     &lt;div id="myDiv"&gt;&lt;/div&gt;
    &lt;br /&gt;
    &lt;br /&gt;
     &lt;div id="myNewDiv"&gt;&lt;/div &gt; 
     &lt;br /&gt;
     &lt;form&gt;
     &lt;input name="textbox" id="textbox" type="text" /&gt;
     &lt;input name="buttonExecute" onclick="getUser(document.getElementById('textbox').value)" type="button" value="Get User"    /&gt;
     &lt;/form&gt;
</code></pre>

<p>What's wrong with this apparoach? </p>

<p>Thanks in advance for your valuable help...<br>
mrana</p>
