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? Quote 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 (edited) 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); }); }); Edited February 5, 2013 by requinix Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/274056-getting-a-selected-id/#findComment-1410528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.