Jump to content

Need help to make a small adjustment on script


thaidomizil

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 ?

 

 

Archived

This topic is now archived and is closed to further replies.

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