javascript - How can I capture form options on submit? -
how can capture form options on submit?
i have plain html form can call javascript function on exit, how capture chosen option <select>
element?
please see code below:
<legend>administration:</legend> <script type="text/javascript"> function handleit(m){ alert("hello"); } </script> </head> <body> <form action="javascript:handleit(select.name)"/> <select name="num" required> <option value="1">add anouncment</option> <option value="2">del anouncment</option> <option value="3">aprove </option> <option value="4">unaprove </option> </select> <input name="anouncement" type="text" required> <input name="submit" type="submit" value="update"/> </form>
first of all, there errors in html syntax.
this data when 'submit' button pressed (jsfiddle):
$('#submit_btn').on('click', function(e) { e.preventdefault(); console.log($('[name="num"]').val()); }); <form id="main-form" method="get"> <select name="num" required> <option value="1">add anouncment</option> <option value="2">del anouncment</option> <option value="3">aprove </option> <option value="4">unaprove </option> </select> <input name="anouncement" type="text" required> <input name="submit" type="button" value="update" id="submit_btn"/> </form>
Comments
Post a Comment