passing and using a variable from one js function to another

I have this code:

The changeFunc grabs a variable and assigns it to tmpScr

The it calls the function loadXMLDoc()

In the line that reads:

xmlhttp.open("GET","update.asp?arma=" . tmpScr. ",true);

I want tmScr to be like:
xmlhttp.open("GET","update.asp?arma=tmpScr",true); (Whatever value it has into line 24)

I have 2 questions:

1. How do I pass the variable (tmpScr)

2. How do I insert it in the I need



function changeFunc() {
    var select1 = document.getElementById("armadora");
var tmpStr = "";
for (var i = 0; i < select1.length; i++) {
        if (select1.options[i].selected)
            tmpStr = select1.options[i].value;
            
    }
    //alert(tmpStr);
    loadXMLDoc();
   }
	
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","update.asp?arma=" . tmpScr. ",true);
xmlhttp.send();
//document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}

Open in new window

robrodpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Declare the variable outside any function then it becomes a global variable that you can use in any function

var myVar;
function someFunction1(){}
function someFunction2(){}

Open in new window

0
Shaun KlineLead Software EngineerCommented:
You can use the plus symbol to concatenate strings and variables together:
xmlhttp.open("GET","update.asp?arma=" + tmpScr, true);
0
robrodpAuthor Commented:
Now how do I concatenate that into my line 24
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GaryCommented:
See the comment above by Shaun, which I undeleted.

Remove this var tmpStr = ""; from inside the function once you have added this before the function
var tmpStr;
0
robrodpAuthor Commented:
I dont't get your last comment . I have no var tmpStr = "";
0
GaryCommented:
function changeFunc() {
    var select1 = document.getElementById("armadora");
var tmpStr = "";


Just put before that function

var tmpStr;
0
robrodpAuthor Commented:
I saw it... removed
0
robrodpAuthor Commented:
For some reasonit is not passing the variable.

If I hard code it it does its job.
xmlhttp.open("GET","update.asp?arma=something", true);

if tmpScr=something
If I leave it concatenated to doesn´t (xmlhttp.open("GET","update.asp?arma=" + tmpScr, true);
0
GaryCommented:
Post your code as you have it.
0
robrodpAuthor Commented:
Sorry I had a Typo

Getting there

Thx Gary
0
GaryCommented:
That code you are using is very old unless you really need to support IE6 and lower you can just replace your loadXMLDoc() function with this

function loadXMLDoc()
{
    var xmlhttp = new XMLHttpRequest(); 
    xmlhttp.open("GET","update.asp?arma=" . tmpScr. ",true);
    xmlhttp.send();
    //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robrodpAuthor Commented:
Thx Gary...

That sounds excellent

Roberto
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.