javascript - use jquery to change a link on a button when two options are selected -


hi want create simple search form when user selects option 1 displays specific options. want link on button take them page on website.

i have code thread works great (without button) how make button if animal selected in first box wolf selected in second box button link change www.mysite.com/wolf.html?

thanks

$("#select1").change(function() {    if ($(this).data('options') == undefined) {      /*taking array of options-2 , kind of embedding on select1*/      $(this).data('options', $('#select2 option').clone());    }    var id = $(this).val();    var options = $(this).data('options').filter('[value=' + id + ']');    $('#select2').html(options);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>  <select name="select1" id="select1">    <option value="1">fruit</option>    <option value="2">animal</option>    <option value="3">bird</option>    <option value="4">car</option>  </select>      <select name="select2" id="select2">    <option value="1">banana</option>    <option value="1">apple</option>    <option value="1">orange</option>    <option value="2">wolf</option>    <option value="2">fox</option>    <option value="2">bear</option>    <option value="3">eagle</option>    <option value="3">hawk</option>    <option value="4">bwm<option>  </select>

use this:

html:

<select name="select1" id="select1">   <option value="1">fruit</option>   <option value="2">animal</option>   <option value="3">bird</option>   <option value="4">car</option> </select>   <select name="select2" id="select2">   <option value="1">banana</option>   <option value="1">apple</option>   <option value="1">orange</option>   <option value="2">wolf</option>   <option value="2">fox</option>   <option value="2">bear</option>   <option value="3">eagle</option>   <option value="3">hawk</option>   <option value="4">bwm<option> </select>  <a href="" ></a> 

js:

$("#select1").change(function() {   if ($(this).data('options') == undefined) {     /*taking array of options-2 , kind of embedding on select1*/     $(this).data('options', $('#select2 option').clone());   }   var id = $(this).val();   var options = $(this).data('options').filter('[value=' + id + ']');   $('#select2').html(options);   var link = 'www.mysite.com/'+ $('#select2 :selected').text() +'.html';   $('a').attr({href:link}).text(link); });  $("#select2").change(function() { var link = 'www.mysite.com/'+ $("option:selected", this).text() +'.html';   $('a').attr({href:link}).text(link); }); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -