javascript - How to get select box value in a href tag -
how select box value in href tag php variable?
<script type="text/javascript"> $(document).ready(function(){ $("select.id").change(function(){ var selectedid = $(".id option:selected").val(); alert(selectedid); }); }); </script> <label>select id</label> <select class="id"> <option value="">select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="4">5</option> </select> <a href="test.php?id=id">testing</a>
code shown below, tested , works 100%, use jquery attr
, give id hyperlink, here id "link":
<a id="link" href="test.php?id=id">testing</a> <!-- give id, else affect entire hyperlinks on project --> $(document).ready(function(){ $("select.id").change(function(){ var selectedid = $(".id option:selected").val(); $("#link").attr("href","test.php?id="+selectedid); //-----this change href }); });
Comments
Post a Comment