robrodp
asked on
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",tr ue); (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
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
I want tmScr to be like:
xmlhttp.open("GET","update
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;
}
You can use the plus symbol to concatenate strings and variables together:
xmlhttp.open("GET","update .asp?arma= " + tmpScr, true);
xmlhttp.open("GET","update
ASKER
Now how do I concatenate that into my line 24
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;
Remove this var tmpStr = ""; from inside the function once you have added this before the function
var tmpStr;
ASKER
I dont't get your last comment . I have no var tmpStr = "";
function changeFunc() {
var select1 = document.getElementById("a rmadora");
var tmpStr = "";
Just put before that function
var tmpStr;
var select1 = document.getElementById("a
var tmpStr = "";
Just put before that function
var tmpStr;
ASKER
I saw it... removed
ASKER
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","updat e.asp?arma =" + tmpScr, true);
If I hard code it it does its job.
xmlhttp.open("GET","update
if tmpScr=something
If I leave it concatenated to doesn´t (xmlhttp.open("GET","updat
Post your code as you have it.
ASKER
Sorry I had a Typo
Getting there
Thx Gary
Getting there
Thx Gary
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx Gary...
That sounds excellent
Roberto
That sounds excellent
Roberto
Open in new window