I’ve searched a bit for this answer, so here is what I’m trying to do – if possible
function foo(variable){
If I call the function, how would I go about passing that parameter as a variable?
function foo(9){
var stuff = 9;
//then pass variable to rest of script
Here is the whole code:
function ajaxgetter(variable) {
var stuff = variable;
var mygetrequest = new ajaxRequest();
mygetrequest.onreadystatechange = function() {
if (mygetrequest.readyState == 4){
if (mygetrequest.status == 200 || window.location.href.indexOf("http") == -1){
document.getElementById("result").innerHTML = mygetrequest.responseText;
} else {
alert("An error has occured making the request");
}
}
}
var namevalue = encodeURIComponent(document.getElementById("name9"+stuff).value);
var agevalue = encodeURIComponent(document.getElementById("age9"+stuff).value);
var utvalue = encodeURIComponent(document.getElementById("ut9"+stuff).value);
document.getElementById("result").innerHTML = "<center><b>Loading...</b></center><br><center><img src='images/ajax-loader1.gif' /></center>";
mygetrequest.open("GET", "newdealerfinder.php?location="+namevalue+"&distance="+agevalue+"&ut="+utvalue1"&r="+ Math.random(), true)mygetrequest.send(null);
}
Onclick event (PHP):
$javacounter = 1;
if($miles1 > 2) {
echo "<form action='' method='get' />
<input type='hidden' value='$city->lat,$city->lng' id='name9$javacounter' name='name9$javacounter' />
<input type='hidden' value='$currentunixtime' id='ut9$javacounter' name='ut9$javacounter' />
<input type='hidden' value='$distance' id='age9$javacounter' name='age9$javacounter' />
<input type='button' value='Coming Soon' onClick='ajaxgetter($javacounter)' />
</form>";
$javacounter++;
}
Location of script:
Here
If this is your function definition
Then you call it and pass a value like so
Not sure what the “rest of script” is. But if you’re looking for this to be accessed outside the function, you need to do some research on Javascript variable scope and using globals (as opposed to passing arguments).
Tho you can return a variable from your function in order to use it throughout the script as well. I updated the code the show that…