How To Get Textbox Value Using Javascript From A HTML (Webpage )Form
I am going to explain how to get values from forms.First you need to write html code of the from.And then you need the java script code to get text box value.
HTML code
<form action=targetfilename.php name=formname method=post>
<table width="400" border="0">
<tr>
<td>User Name </td>
<td> <input type=text name=name></td>
</tr>
<tr>
<td>Password </td>
<td> <input type=text name=pass></td>
</tr>
<tr>
<td>Confirm Password </td>
<td> <input type=text name=cpass></td>
</tr>
</table>
</form>
I am going to explain how to get values from forms.First you need to write html code of the from.And then you need the java script code to get text box value.
HTML code
<form action=targetfilename.php name=formname method=post>
<table width="400" border="0">
<tr>
<td>User Name </td>
<td> <input type=text name=name></td>
</tr>
<tr>
<td>Password </td>
<td> <input type=text name=pass></td>
</tr>
<tr>
<td>Confirm Password </td>
<td> <input type=text name=cpass></td>
</tr>
</table>
</form>
Java script
<script>
function check()
{
var pass=document.formname.pass.value;
var cpass= document.formname.cpass.value;
if(cpass==pass)
{
alert("password maches");
}
}
</script>
<script>
function check()
{
var pass=document.formname.pass.value;
var cpass= document.formname.cpass.value;
if(cpass==pass)
{
alert("password maches");
}
}
</script>
Example code to check the passwords are matching or not and alert box if matching
<form action=register.php name=fo method=post>
<table width="400" border="0">
<tr>
<td>User Name </td>
<td> <input type=text name=name></td>
</tr>
<tr>
<td>Password </td>
<td> <input type=text name=pass></td>
</tr>
<tr>
<td>Confirm Password </td>
<td> <input type=text name=cpass></td>
</tr>
</table>
<form action=register.php name=fo method=post>
<table width="400" border="0">
<tr>
<td>User Name </td>
<td> <input type=text name=name></td>
</tr>
<tr>
<td>Password </td>
<td> <input type=text name=pass></td>
</tr>
<tr>
<td>Confirm Password </td>
<td> <input type=text name=cpass></td>
</tr>
</table>
<script>
function check()
{
var pass= document.fo.pass.value;
var cpass= document.fo.cpass.value;
if(cpass==pass)
{
alert("password matches");
}
else
function check()
{
var pass= document.fo.pass.value;
var cpass= document.fo.cpass.value;
if(cpass==pass)
{
alert("password matches");
}
else
{
alert("password not matches");
}
}
</script>
<br >
</div>
<input type=submit value=Register onMouseOver="check()";>
</form>
alert("password not matches");
}
}
</script>
<br >
</div>
<input type=submit value=Register onMouseOver="check()";>
</form>
No comments:
Post a Comment
Post Your valuable comments here ..........