javascript - jquery form only passing first select box values on submit -


i'm new posting here, have visited several times on years read every ones ideas.

my issue have form 2 select boxes, second 1 populated values upon selection in first. second holds url value got upon submit. function works using onchange on submit first of second select list urls work. can swap them first works, others pass primary url followed crosshatch '#'.

<script> $(document).ready(function($){  $("#category").change(function() {     $('select[name="product"]').removeattr("name").hide();     $("#" + $(this).val()).show().attr("name", "product"); });  /* ' works on $(".product").change(function() {     document.location = $(this).val(); }); */  /* passes url on first product option list else passes opening url + #*/ $('#discover').submit(function() {             document.location = $(".product").val();     return false; });  });  </script>  <div id="discover-box"> <form id="discover" method="post"> <fieldset> <p class="category">  <label class="title">category:</label> <select id="category" name="category">         <option value="#" selected="selected">choose category</option>         <option value="accommodation">accommodation</option>         <option value="food">food</option>         <option value="explore">explore</option> </select>  <p><label>sub-category:</label>  <select id="accommodation" name="product" class="product"> <option value="#" selected="selected">choose sub-category</option> <option value="accommodation_category.asp?o=1&c=1">motels</option> <option value="accommodation_category.asp?o=2&c=2">camping, caravan & holiday parks</option> <option value="accommodation_category.asp?o=3&c=3">b&b, self-contained houses & cottages</option> <option value="accommodation_category.asp?o=4&c=4">hotels</option> <option value="accommodation_category.asp?o=5&c=5">backpackers & group accommodation</option>         <option value="accommodation_category.asp?o=6&c=6">national parks</option> </select>  <select id="food" style="display:none" name="product" class="product"> <option value="#" selected="selected">choose sub-category</option> <option value="food_wine_category.asp?o=1&t=1&c=1">restaurants & cafes</option> <option value="food_wine_category.asp?o=2&t=1&c=2">pubs</option> <option value="food_wine_category.asp?o=3&t=1&c=3">bakeries & takeaway</option> <option value="food_wine_category.asp?o=4&t=1&c=4">local produce</option> <option value="food_wine_category.asp?o=5&t=2&c=1">mount gambier wine region</option> <option value="food_wine_category.asp?o=5&t=2&c=2">other limestone coast wine regions</option> </select>  <select id="explore" style="display:none" name="product" class="product"> <option value="#" selected="selected">choose sub-category</option> <option value="explore_category.asp?o=1">top 10</option> <option value="explore_category.asp?o=2">arts, crafts, galleries & museums</option> <option value="explore_category.asp?o=3">heritage, antiques & collectables</option> <option value="explore_category.asp?o=4">family fun</option> <option value="explore_category.asp?o=5">caves & sinkholes</option> <option value="explore_category.asp?o=6">parks & gardens</option> <option value="explore_category.asp?o=7">walks & drives</option> <option value="explore_category.asp?o=8">kanawinka geotrail</option> <option value="explore_category.asp?o=9">retail</option> <option value="explore_category.asp?o=10">recreation, leisure & adventure</option>   </select>  </p> <p class="buttons">         <input type="image" src="images/submit-red.png" value="submit"> </p>  </fieldset> </form> </div> 

because $(".product").val(); find first occurrence of dom having class product in case fetch first one... u can using

$('#discover').submit(function() {            document.location = $('select[name="product"]').val();    return false; }); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -