bear23
asked on
web textbox validation
I have a webpage that has 2 textboxes and 1 submit button. When the user hits the submit button it calls another file that submits data to an email account and then the page displays saying sent....
I need something to make sure the textboxes have data in it before it calls the other file.
any ideas.
I need something to make sure the textboxes have data in it before it calls the other file.
any ideas.
Hello,
What languages are you using? If you use JavaScript, your user can disable JavaScript and do what they don't expected to do. So I think it is Server side script. Is it PHP, Perl, ASP.NET, JSP .... Please tell more details.
What languages are you using? If you use JavaScript, your user can disable JavaScript and do what they don't expected to do. So I think it is Server side script. Is it PHP, Perl, ASP.NET, JSP .... Please tell more details.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi bear,
Just an additional note:
In general there are always two possibilities to validate a form:
a) client side
b) server side
The expert rdivilbiss shows how to use both methods. First he validates the form using javascript (client side) and then, using ASP, doing the validation (well - a check for existance) on the server side.
Javascript validation depends on the users settings and it is NOT a secure validation (turn off javascript get rid of any validation). Server side validation is (and that's my personal view) a secure, proper thing to do - but a far way to go just to validate a simple form field :) .
Best practice: use both, as rdivilbiss suggests - javascript is user friendly and produces for the user a fast answer - server side is proper and more secure.
BTW: if its some formmailer stuff - watch out that it can't be abused by some Bots to send out spam mails. Do this on the server side.
-K
Just an additional note:
In general there are always two possibilities to validate a form:
a) client side
b) server side
The expert rdivilbiss shows how to use both methods. First he validates the form using javascript (client side) and then, using ASP, doing the validation (well - a check for existance) on the server side.
Javascript validation depends on the users settings and it is NOT a secure validation (turn off javascript get rid of any validation). Server side validation is (and that's my personal view) a secure, proper thing to do - but a far way to go just to validate a simple form field :) .
Best practice: use both, as rdivilbiss suggests - javascript is user friendly and produces for the user a fast answer - server side is proper and more secure.
BTW: if its some formmailer stuff - watch out that it can't be abused by some Bots to send out spam mails. Do this on the server side.
-K
you can use the onsubmit property of your form to do so, in ex:
onsubmit="return !(field_a.value==''||field _b.value== '')"
note: '' is twice the ' (empty string), dont confuse them with "
the value returned to onsubmit method is ignored by some browsers witch will submit the form anyway, it works fine on IE
in any case its a good idea to check them in the server again.
complete example:
<html><body>
<form onsubmit="return !(field_a.value==''||field _b.value== '')">
<input id=field_a><br>
<input id=field_b><br>
<input type=submit>
</form>
</body></html>
you can have a more elaborate function to validate the form and present messages in error case, just do a validation function and then call it from the onsubmit prop.
onsubmit="return !(field_a.value==''||field
note: '' is twice the ' (empty string), dont confuse them with "
the value returned to onsubmit method is ignored by some browsers witch will submit the form anyway, it works fine on IE
in any case its a good idea to check them in the server again.
complete example:
<html><body>
<form onsubmit="return !(field_a.value==''||field
<input id=field_a><br>
<input id=field_b><br>
<input type=submit>
</form>
</body></html>
you can have a more elaborate function to validate the form and present messages in error case, just do a validation function and then call it from the onsubmit prop.
oops.. it works that way for <input> fields, if you use <textarea> objects then you gota use innerText property instead of value
From the Toolbox, drag a RequiredField Validator to your form
Set its ControlToValidate property to one of your textboxes name, and Type into the Error Message property the message you want to appear.
Repeat the process for your other textbox
This is assuming you are using ASP.NET...
Dabas