Table of Contents
hide
Submit Related Codes
function formSubmit()
{
document.getElementById("form1").submit();
}
<!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
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>
<!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>
0 Comments