javascript - How to separate two forms in a page -
i have 2 forms in page when click on 1 button other form runs , >>>two windows of same page<<< open. how can separate function of these 2 or more forms in page?
the code below. form has same code different web addresses.
<form method="post"> <input id="element 1_1" class="element radio1" name="element 1" type="radio" value="http://www.yahoo.com" /> model 13<br/> <br/> <input id="element 2_1" class="element radio1" name="element 1" type="radio" value="http://www.msn.com" /> model 17<br/><br/> <input id="element 3_1" class="element radio1" name="element 1" type="radio" value="http://www.ebay.com" /> model 22 <br/><br/> <script> $(function () { $("form").submit(function (e) { e.preventdefault(); var url = $(this).find('input[type="radio"]:checked').val(); window.open(url); }); }); </script></form>
other coder
<form method="post"> <input id="element 1_2" class="element radio" name="element 2" type="radio" value="http://www.123.com" /> model 5 - 8<br/> <br/> <input id="element 2_2" class="element radio" name="element 2" type="radio" value="http://www.543.com" /> model 6-10<br/> <br/> <script> $(function () { $("form").submit(function (e) { e.preventdefault(); var url = $(this).find('input[type="radio"]:checked').val(); window.open(url); }); }); </script></form>
you can use attribute id
each form.
<form method="post" id="form1"> ... </form> <form method="post" id="form2"> ... </form> <script> $(function () { $("#form1").submit(function(e) { // function form1 }); $("#form2").submit(function(e) { // function form2 }); }); </script>
Comments
Post a Comment