gerkintrigg Posted February 5, 2013 Share Posted February 5, 2013 I'm making an ajax query to allow my select box to parse a selected id to an ajax query using this code: <select name="top_cat<?php echo $r['product_id'];?>" id="top_cat<?php echo $r['product_id'];?>" onchange="javascript: MyAjaxRequest('sub_cat_selector<?php echo $r['product_id'];?>','sub_cat_selector.php?id='+top_cat<?php echo $r['product_id'];?>.value);"> It doesn't work and I think I may be making a very silly mistake. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/274056-getting-a-selected-id/ Share on other sites More sharing options...
requinix Posted February 5, 2013 Share Posted February 5, 2013 this.value is easier. 'sub_cat_selector.php?id='+this.value Have you checked that sub_cat_selector.php is being invoked? With the right ID? And is correctly doing whatever it's supposed to be doing? [edit] Oh, and remove the "javascript:" from the onchange. That's only for link hrefs. onchange contains Javascript code already, you don't have to tell it again. And actually that may be the problem... [edit 2] Oh, and try to avoid inline Javascript. If you have something like jQuery then you can quite easily do a <select name="top_cat<?php echo $r['product_id'];?>" id="top_cat<?php echo $r['product_id'];?>" class="top_cat"> $(function() { $("select.top_cat").change(function() { MyAjaxRequest(this.id.replace(/top_cat/, "sub_cat_selector"), "sub_cat_selector.php?id=" + this.value); }); }); Link to comment https://forums.phpfreaks.com/topic/274056-getting-a-selected-id/#findComment-1410321 Share on other sites More sharing options...
gerkintrigg Posted February 6, 2013 Author Share Posted February 6, 2013 the sub cat selector is being invoked... I ended up doing it by href in the end (it's only for a back end system) but it's rather annoying that I can't get it working as a jump menu... I did it before with another form, but this is playing up. Link to comment https://forums.phpfreaks.com/topic/274056-getting-a-selected-id/#findComment-1410528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.