submit problem (Full Version)

All Forums >> [Web Development] >> General Web Development



Message


wizard_oz -> submit problem (2/11/2008 13:46:30)

Hi, I have a problem with checking some fields before click the SUBMIT button. I would like to check the fields and if the feilds are empty I would give a message that say "the feild is empty" and if not, continue to the next page
my code is simple and look like:
<form action="InsertDB.asp" method="get" id="form1" name="form1">
	<input id="UserName" name="UserName" class="ghi" >
	<INPUT type="submit" value="Submit" id=submit2 name=submit2>
</FORM>


any Idea PLEASE....




ou812 -> RE: submit problem (2/11/2008 14:17:12)

Lots of folks use JavaScript for this type of checking. Here are just a few examples:
http://javascript.internet.com/forms/personal-details-validation.html
http://javascript.internet.com/forms/required-fields.html
http://javascript.internet.com/forms/ultimate-form-validator.html

The site has many more: http://javascript.internet.com/forms/

Or you could check using ASP, after they submit, checking for the empty fields and then redirect them back to the form.




Catherine Sea -> RE: submit problem (2/25/2008 20:22:56)

You can use the event handler called onsubmit to check the fields.
Below is the code:
<script language="javascript">
function checkfields()
{
var txtUserName = document.getElementById("UserName");
if(txtUserName && txtUserName.value == "")
{
alert("the feild is empty");
return false;
}
}
</script>
<form action="InsertDB.asp" method="get" id="form1" name="form1" onsubmit="return checkfields()">
<input id="UserName" name="UserName" class="ghi" >
<INPUT type="submit" value="Submit" id=submit2 name=submit2 >
</FORM>


This code works well.
I hope this will help you.

--
Catherine Sea
http://www.dynamsoft.com/




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625