mo Posted May 12, 2009 Share Posted May 12, 2009 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> ?> Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/ Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 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. Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/#findComment-832746 Share on other sites More sharing options...
mo Posted May 12, 2009 Author Share Posted May 12, 2009 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/#findComment-832753 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 <select name=\"OrderStatus\" size=\"1\" onchange=\"ajaxRequest('statusUpd.php', 'val='+$F('this.selectedIndex'))\"> Near the end, is $F a JavaScript function? Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/#findComment-832756 Share on other sites More sharing options...
mo Posted May 12, 2009 Author Share Posted May 12, 2009 <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. Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/#findComment-832778 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 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))+"\"> Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/#findComment-832830 Share on other sites More sharing options...
mo Posted May 13, 2009 Author Share Posted May 13, 2009 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. Link to comment https://forums.phpfreaks.com/topic/157875-solved-select-option-onchange-call-ajax-function-not-working-works-on-link/#findComment-833173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.