Change action link in a form when selecting an option with jquery

I want to change the action link in the form when selecting an option. The code below should change the action link when the 31 days option is selected. But i cant get it to work. And i do not see any errors in console. Have i missed something?

My jquery script:

<script type="text/JavaScript">
$("#zomlink").change(function() {
  var action = $(this).val() == "1906104";
  $("#buyvipform").attr("action", "http://www.somelink.com/?ref54434.swe");
});
</script>

My form code:

<form method="post" id="buyvipform" name="buyvipform" class="buyvipform" action="https://www.changethislink.com">

<select name="zomlink" id="zomlink" style="margin-top: 290px;">
<option value="1906083">3 days Trial (2€)</option>
<option value="1906104">31 days (19€)</option>
<option value="1906125">90 days (50€)</option>
<option value="1906146">365 days (99€)</option>
</select>


<input type="submit" value="" style="background:url(<?php bloginfo('template_directory'); ?>/images/buy.png) no-repeat; width: 106px; height: 40px; border: 0px;">

</form>

Upvotes: 0

Views: 623

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82251

You need to get the selected option value on change of select. and then if it has value 1906104, change the href url:

$("#zomlink").change(function() {
 if($(this).val() == "1906104")
   $("#buyvipform").attr("action", "http://www.somelink.com/?ref54434.swe");
});

Working Demo

Upvotes: 2

Related Questions