Jump to content

Recommended Posts

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 !

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

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 ?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.