Submit Related Codes

         

Example : How to submit an html form by clicking a button in a html page using java script ?
function formSubmit()
{
     document.getElementById("form1").submit();
} 
Example : How to identify a submit button from multiple submit buttons in an html page using java script ?
<!DOCTYPE html>
<html>
    <head>        
        <title>Codershelpline</title>
    </head>
    <body>
        <form onsubmit="alert(this.submited); return false;">
            <input type="submit" value="Yes" onclick="this.form.submited=this.value;">
            <input type="submit" value="No" onclick="this.form.submited=this.value;">           
        </form>
    </body>
</html>

----------------------------  OR  ------------------------------
<!DOCTYPE html>
<html>
    <head>        
        <title>Codershelpline</title>
    </head>
    <body>
        <form onsubmit="var x=(this.submited);alert(x); return false;">
            <input type="submit" value="Yes" onclick="this.form.submited=this.value;">
            <input type="submit" value="No" onclick="this.form.submited=this.value;">           
        </form>
    </body>
</html>

Reset Related Codes

Example : How to Reset an html form by clicking a button in a html page using java script code ?
function formReset()
{
document.getElementById("form1").reset();
} 

Button Related Codes

        

Example : How to close the web page application.
<!DOCTYPE html>
<html>

    <head>        
        <title>Codershelpline</title>
    </head>

    <body>
        <form name="form1" method="post" action="#">            
            <input type="button" value="Exit" onclick="window.close();">            
        </form>
    </body>
</html>
Example : How to make a text box empty/blank in an html page on clicking a button . 
<!DOCTYPE html>
   <html>
      <body>         
         <input type="text" value="India" id="txtid">
         <input type="button" value="Cancel" onclick="document.getElementById('txtid').value = '' ">
      </body>
   </html>

———————————————-  OR  ———————————————–

<!DOCTYPE html>
<html>
    <head>        
        <title>Codershelpline Clear Code</title>
        <script>
            function Cancel()
            {                
                document.getElementById("TxtSlno2").value="";
                document.getElementById("TxtSname2").value="";
                document.getElementById("TxaAddr2").value="";                
                
                document.getElementById("RdbMale").checked=false;
                document.getElementById("RdbFemale").checked=false;
                document.getElementById("RdbOther").checked=false;
                
                document.getElementById("TxtUname2").value="";

                document.getElementById("TxtPassword2").value="";
                document.getElementById("TxtCpassword2").value="";

                document.getElementById("DtpDob2").value="";

                document.getElementById("TxtMobno2").value="";

                document.getElementById("TxtEmail2").value="";

                document.getElementById("CmbSecQues2").value="";
                document.getElementById("TxtSecAns2").value="";
                
                document.getElementById("ChkCricket2").checked=false;
                document.getElementById("ChkDance2").checked=false;
                document.getElementById("ChkMusic2").checked=false;

                document.getElementById("TxtRem2").value="";
            }
        </script>
     
    </head>
    <body>
      <form name="form1" id="form2" action="#" method="post">
	 <center>
	    <fieldset style="width: 60%">				
		<legend>Create New Student Account</legend>
		   <table name="tab1" id="tab2">
		      
		      <tr>
			  <td>Serial No.</td>
			  <td>:</td>
			  <td><input type="text" name="TxtSlno1" id="TxtSlno2"></td>
		      </tr>
			   
		      <tr>
			  <td>Student Name</td>
			  <td>:</td>
			  <td><input type="text" name="TxtSname1" id="TxtSname2" 
                               value="Codershelpline" onfocus="this.value=''">
                          </td>
		      </tr>
			   
		      <tr>
			  <td>Address</td>
			  <td>:</td>
			  <td>
			     <textarea cols="35" rows="5" name="TxaAddr1" id="TxaAddr2">
                             </textarea>							
			  </td>
		      </tr>
			   
		      <tr>
			  <td>Sex</td>
			  <td>:</td>
		          <td>
				<input type="radio" name="Rdbsex" id="RdbMale" value="Male">Male
				<input type="radio" name="Rdbsex" id="RdbFemale" value="Female">
                                       Female
				<input type="radio" name="Rdbsex" id="RdbOther" value="Other">
                                       Other
		          </td>
		      </tr>
			   
		      <tr>
			  <td>User Name</td>
			  <td>:</td>
			  <td><input type="text" name="TxtUname1" id="TxtUname2"></td>
		      </tr>
			   
		      <tr>
			  <td>Password</td>
			  <td>:</td>
			  <td><input type="password" name="TxtPassword1" id="TxtPassword2"></td>
		      </tr>
			   
		      <tr>
			  <td>Confirm Password</td>
			  <td>:</td>
			  <td><input type="password" name="TxtCpassword1" id="TxtCpassword2"></td>
		      </tr>
			   
		      <tr>
		          <td>DOB</td>
			  <td>:</td>
			  <td><input type="date" name="DtpDob1" id="DtpDob2"></td>
		      </tr>
			   
		      <tr>
			  <td>Mobile No.</td>
			  <td>:</td>
			  <td><input type="Number" name="TxtMobno1" id="TxtMobno2"></td>
		      </tr>
			   
		      <tr>
			   <td>Email</td>
			   <td>:</td>
			   <td><input type="text" name="TxtEmail1" id="TxtEmail2"></td>
		      </tr>
			   
		      <tr>
			    <td>Security Questions</td>
			    <td>:</td>
			    <td>
   				<select name="CmbSecQues1" id="CmbSecQues2">
       				   <option value="Choose One">Choose One</option>
       				   <option value="What is Your Favourite Book">What is Your Favourite 
                                       Book</option>
       				   <option value="What is Your Favourite Teacher">What is Your 
                                       Favourite Teacher</option>
       				   <option value="What is Your Favourate Place">What is Your 
                                       Favourate Place</option> 
       				   <option value="What is Your Favourate Pets">What is Your Favourate 
                                       Pets</option>
   				</select>
			     </td>
		     </tr>
			   
		     <tr>
			     <td>Security Answer</td>
			     <td>:</td>
			     <td><input type="text" name="TxtSecAns1" id="TxtSecAns2"></td>
		     </tr>
			   
		     <tr>
			     <td>Hobbies</td>
			     <td>:</td>
			     <td>
			   	<input type="checkbox" name="ChkCricket1" id="ChkCricket2" 
                                       value="Cricket">Cricket
			   	<input type="checkbox" name="ChkDance1" id="ChkDance2" 
                                       value="Dance">Dance
			   	<input type="checkbox" name="ChkMusic1" id="ChkMusic2" 
                                       value="Music">Music			   
			     </td>
		    </tr>
			   
		    <tr>
			     <td>Remarks</td>
			     <td>:</td>
			     <td><input type="text" name="TxtRem1" id="TxtRem2" value="N/A"></td>
		    </tr>
			   
		    <tr>
			     <td></td>
			     <td></td>
			     <td><input type="submit" name="BtnSave1" id="BtnSave2" value="Save">
                                 
                                 <input type="button" name="BtnReset1" id="BtnReset2" value="Clear" 
                                        onclick="Cancel()">                                
			     </td>
		     </tr>
		   </table>
	       </fieldset>
            </center>
	 </form>
      </body>   
</html>

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.