Jump to content

[SOLVED] Select Option onchange call AJAX function not working works on link


mo

Recommended Posts

I have an AJAX function that I found online in which you can specify a php file to call and pass values. I have included the AJAX core files and this script works on another part of my site where I call the function via a link (<a href.</a>) but not when I try calling it on a select option onchange.

 

The function is as follows:

<script type=\"text/javascript\">   
			function ajaxRequest(url,data) {
				var aj = new Ajax.Request(url, {
				method:'get',
				parameters: data,
				onComplete: getResponse
				}
				);   
			}   
			/* ajax.Response */  
			function getResponse(oReq) {
				$('result').innerHTML = oReq.responseText;   
			}   
		</script>

 

This code works if I use it in a manner like below.

 

<?php
<a href=\"javascript:ajaxRequest('rating.php', 'val='+$F('1-".$_GET['storeid']."'))\" title=\"1 star out of 5\" class=\"one-star\">1</a>
?>

 

However, when I use is as follows, nothing happens.

 

<?php
<select name=\"OrderStatus\" size=\"1\" onchange=\"ajaxRequest('statusUpd.php', 'val='+$F('this.selectedIndex'))\">
<option value=\"NEW\">New</option>
<option value=\"CANCELLED\">Cancelled</option>
<option value=\"COMPLETE\">Complete</option>
</select>
?>

If I were you, I would check my quotes. See how you have a giant red blob of text? That usually mean your quotes are not closed correctly.

 

Thanks. This is not how the actual code is formatted. I just pasted the option tags there for a visual. Actual code is below.

 

<?php
echo "<td class=\"$tintClass\">
			<select name=\"OrderStatus\" size=\"1\" onchange=\"ajaxRequest('statusUpd.php', 'val='+$F('this.selectedIndex'))\">";							

if(strtoupper($Row['od_status']) == 'NEW'){
	echo "<option name=\"ItmOrderStatus\" value=\"New\" selected>New</option>";
}else{
	echo "<option name=\"ItmOrderStatus\" value=\"New\">New</option>";
}
if(strtoupper($Row['od_status']) == 'IN ROUTE'){
	echo "<option value=\"In Route\" selected>In Route</option>";
}else{
	echo "<option value=\"In Route\">In Route</option>";
}
if(strtoupper($Row['od_status']) == 'CANCELLED'){
	echo "<option value=\"Cancelled\" selected>Cancelled</option>";
	$tintClass = "dataListItemCancel";
}else{
	echo "<option value=\"Cancelled\">Cancelled</option>";
}
if(strtoupper($Row['od_status']) == 'COMPLETE'){
	echo "<option value=\"Complete\" selected>Complete</option>";
}else{
	echo "<option value=\"Complete\">Complete</option>";
}
if(strtoupper($Row['od_status']) == 'ON HOLD'){
	echo "<option value=\"On Hold\" selected>On Hold</option>";
}else{
	echo "<option value=\"On Hold\">On Hold</option>";
}

echo "</select>
                <div id=\"result\"></div></td>";
?>

<select name=\"OrderStatus\" size=\"1\" onchange=\"ajaxRequest('statusUpd.php', 'val='+$F('this.selectedIndex'))\">

Near the end, is $F a JavaScript function?

 

I have no idea. This is a script from a ratings script that I found online and it works fine on my ratings page.

Hmm.. well it's hard to help you when I don't know these things, but try this-

<select name=\"OrderStatus\" size=\"1\" onchange=\"ajaxRequest('statusUpd.php', 'val="+$F(this.selectedIndex))+"\">

 

Thanks for your replies. Sorry to waste your time. I forgot to include a javascript file. The function now works.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.