Zack
asked on
Sending multiple variables to AJAX... Newbie question
Hi - This is my code for the HTML
Here is my AJAX script
and the getPayment.inc.php (minus the connection string, etc)
My question is how do I send the variables loc and pmtid both to the ajax script? The loc select will always have something populated in it.
Thanks for your help!
Zack
</center><div style="margin-left:660px";><img src="images/hdr_paymentcodes.png" width="439" height="43" /></div>
<form name="UID" action="./pmta.php" method="post" onsubmit="return formCheck6(this);">
<table Border=0 width=30% align=center cellpadding=5 class="text">
<input type="hidden" name="process" value="process">
<tr><td>Location:</td><td><select name="loc" id="loc" onblur="getPayment(this.value)" >
<?
$b = 0;
while ($b < count($siteadmin)) {
if ($loc == $siteadmin[$b]) {
echo "<option SELECTED value=\"" . $siteadmin[$b] . "\">" . $siteadmin[$b] . "</option>";
}
else {
echo "<option value=\"" . $siteadmin[$b] . "\">" . $siteadmin[$b] . "</option>";
}
$b = ++$b;
}
?>
</select></td></tr>
<tr><td>Payment Code ID:</td><td><input name="pmtid" id="pmtid" style="text-transform: uppercase;" class="DefaultEntry" type="text" maxlength="12" size="20" id="f1" onkeypress="return handleEnter(this, event);" onblur="getPayment(this.value)" value="<? echo $_POST['pmtid']; ?>"></td></tr>
<tr><td>Name:</td><td><input name="pname" id="pname" style="text-transform: propercase;" class="DefaultEntry" onkeypress="return handleEnter(this, event);" type="text" maxlength="45" size="20" value="<? echo $_POST['pname']; ?>"></td></tr>
<tr><td>Active:</td><td><select onkeypress="return handleEnter(this, event);" name="pactive" size=1>
<? if ($_POST['pactive'] == "Y") { echo "<option value=\"Y\" selected=\"yes\">Yes</option>"; } else { echo "<option value=\"Y\">Yes</option>"; }
if ($_POST['pactive'] == "N") { echo "<option value=\"N\" selected=\"yes\">No</option>"; } else { echo "<option value=\"N\">No</option>"; }
?>
</td></tr>
</table>
<center><input type="image" name="submit" class="submit" value="submit" id="submit" src="images/btn_addpmt.png" width="183" height="53" border=0></center>
Here is my AJAX script
function getPayment(str) {
if (str=="") {
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var my_array = xmlhttp.responseText.split("|"); // split by |
if (my_array[1] == null) {
document.getElementById("submit").src = "/ef/images/btn_addpmt.png";
document.getElementById("submit").disabled = false;
return;
}
else {
document.getElementById("submit").src = "/ef/images/btn_addpmtfail.png";
document.getElementById("submit").disabled = true;
alert("Duplicate Payment Code found. Please try again.");
}
}
}
xmlhttp.open("GET","./inc/getPayment.inc.php?q="+str,true);
xmlhttp.send();
}
and the getPayment.inc.php (minus the connection string, etc)
$result = mysql_query($sql);
if($row = mysql_fetch_array($result))
{
echo $row['userid'] . "|" . $row['realname'];
}
My question is how do I send the variables loc and pmtid both to the ajax script? The loc select will always have something populated in it.
Thanks for your help!
Zack
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone!
https://www.experts-exchange.com/articles/10712/The-Hello-World-Exercise-with-jQuery-and-PHP.html