javascript - Unable to add the value from dropdown list to end of url -


i'm having trouble trying add value part of dropdown list end of url each value different dropdown list.

<!doctype html>  <html>    <head>    <title>task 8</title>  </head>    <body>    <script type="text/javascript">      change(val) {        document.staff1.action="http://tl28serv/task7.php?staffid=" + val;      }    </script>      <form id="staffname" action="http://tl28serv/task7.php?staffid=" method="post">      <select id="staff1">        <option value="12">perce trainor</option>        <option value="15">chuck norris</option>        <option value="23">jane zumba</option>      </select>      <br/>      <input type="submit" name="submit">    </form>  </body>    </html>

you missing function keyword. need call function change() on onchange event. this:

  <script type="text/javascript">     function change(th) { //added function keyword       document.getelementbyid("staffname").action="http://tl28serv/task7.php?staffid=" + th.value;     }   </script>    <form id="staffname" action="http://tl28serv/task7.php?staffid=" method="post">     <select id="staff1" onchange="change(this)"> <!--called change() here-->       <option value="12">perce trainor</option>       <option value="15">chuck norris</option>       <option value="23">jane zumba</option>     </select>     <br/>     <input type="submit" name="submit"> </form> 

demo. check console.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -