thaidomizil Posted September 6, 2011 Share Posted September 6, 2011 Hello, i found this script that changes the action of a form based on a dropdown selection, i tried to make it work with my form but it won't work. Can someone help me out here please? This is the code: $("#bookingType").change(function() { var action = $(this).val() == "people" ? "user" : "content"; $("#book-travel-form").attr("action", "/search/" + action); }); Changing the form and select id's isn't the problem, i've done that already, my dropdown has the Values F and FH, what i need is, if F is selected change form action to flug.php if FH is selected change it to flugandh.php, there is also this: ("action", "/search/" + action); which adds a subfolder infront of the url, i tried to remove it but that didn't work too well thank you ! Quote Link to comment https://forums.phpfreaks.com/topic/246549-need-help-to-make-a-small-adjustment-on-script/ Share on other sites More sharing options...
goodacre.liam Posted September 6, 2011 Share Posted September 6, 2011 Do you mean something like this? (function(){ var actionMap = { 'F' : 'flug.php', 'FH' : 'flugandh.php' }; $("#bookingType").change(function() { var action = $(this).val(); if (action in actionMap) { $("#book-travel-form").attr("action", actionMap[action]); } }); }()); The 'actionMap' object defines which action values map to which file. If the action exists in the mapping, then set the action attribute to the corresponding file. Hope this helps, Liam Goodacre Quote Link to comment https://forums.phpfreaks.com/topic/246549-need-help-to-make-a-small-adjustment-on-script/#findComment-1265987 Share on other sites More sharing options...
thaidomizil Posted September 6, 2011 Author Share Posted September 6, 2011 Liam, thank you for your quick reply, i've tried the code quick on a blank page to make sure it works, which it does, thank you for that ! Now i've tried to implement it into my site, i don't know what exactly is the problem but it won't work there, the select is populated through js aswell, does that make any difference ? I also submitted my form with tamper data running to make sure the values and the select name is correct, which they are, but still it won't work. What am i missing ? Quote Link to comment https://forums.phpfreaks.com/topic/246549-need-help-to-make-a-small-adjustment-on-script/#findComment-1265993 Share on other sites More sharing options...
thaidomizil Posted September 6, 2011 Author Share Posted September 6, 2011 I got it working now, removed style="display:none;" from my <li> where the select is sitting inside. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/246549-need-help-to-make-a-small-adjustment-on-script/#findComment-1265998 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.