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
function foo (bar) {..., you are already declaring the function arguments, so when you call foo(9),barwill have value 9 and it exists as a local variable in that function scope (accessible within the scope and inner functions) .