How to get data through form controll using javascript

<!--DOCTYPE html--> <html> <head> <title></title> <script type="text/javascript" src='myjs.js'></script> </head> <body> <form name="myForm" action="" onsubmit="return validateForm()" method="post"> <table align="center" border="1"> <tr> <td>NAME:</td> <td><input type="text" name="fname"></td> </tr> <tr> <td>Email:</td> <td><input type="email" name="eml"></td> </tr> <tr> <td>Mobile:</td> <td><input type="number" name="mob"></td> </tr> <tr> <td>Gender:</td> <td> <input type="radio" name="gen" value="male">Male <input type="radio" name="gen" value="female">Female <input type="radio" name="gen" value="other">Other </td> </tr> <tr> <td>Course:</td> <td> <input type="checkbox" value="BCA" >BCA <input type="checkbox" value="MCA" >MCA <input type="checkbox" value="PHD" >PHD </td> </tr> <tr> <td>Country</td> <td> <select name="country"> <option value="india">India</option> <option value="pakistan">Pakistan</option> </select> </td> </tr> <tr> <td>City</td> <td> <input type="text" name="city" list="city"> <datalist id="city"> <option value="india">India</option> <option value="pakistan">Pakistan</option> </datalist> </td> </tr> <tr> <td>Address</td> <td> <textarea cols="22" rows="4" name="address"> </textarea> </td> </tr> <tr> <td></td> <td><input type="submit" ></td> </tr> </table> </form> </body> </html>

<!--===========[myjs.js file]=================---> function validateForm(){ var nm = document.forms["myForm"]["fname"].value; var eml = document.forms["myForm"]["eml"].value; var mob = document.forms["myForm"]["mob"].value; var gen = document.forms["myForm"]["gen"].value; var course = document.forms["myForm"]["chk"].value; var country = document.forms["myForm"]["country"].value; var city = document.forms["myForm"]["city"].value; var addr = document.forms["myForm"]["address"].value; /*-------[myultiple checkbox]----------------*/ var checkBoxes = document.getElementsByTagName('input'); // alert(checkBoxes.length); var param = "Values of Checkboxes:"+"\n"; for (var i=0;i< checkBoxes.length;i++) { if (checkBoxes[i].checked == true) { param += checkBoxes[i].value + "\n"; } } alert(param); }
Output

agyanadda

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 $type={blogger}:

Post a Comment