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.
bear23Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
Hi bear23:
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
0
dttriCommented:
 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.
0
rdivilbissCommented:
<form method="post" action="nextPageToSendEmail.asp" onsubmit="return validate(this);">
   <input type="text" name="textbox1" ...>
   <input type="text" name="textbox2" ...>
   <input name="submit" type="submit" value="Submit">
</form>

<script>
function validate(oForm) {
    var message='';

    if (oForm.textbox1.value=='') {
        message='You must enter data in TextBox1\n';
    }
    if (oForm.textbox2.value=='') {
        message=message + 'You must enter data in TextBox2';
    }
    if (message=='') {
        return true;
    } else {
        alert(message);
        return false;
    }
}

On the next page that sends e-mail you should also check for data.

If it is ASP, then before the <HTML> tag....

<%
Dim okayToSend
okayToSend = true
if request.form("textbox1") = "" then
    okayToSend = false
end if
if request.form("textbox2") = "" then
    okayToSend = false
end if
if NOT okayToSend then
    response.redirect("thePageWithTheForm.htm")
end if

.... code to send the e-mail

%>
<HTML> .... </HTML>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

guru_kCommented:
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
0
neu-rahCommented:
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.
0
neu-rahCommented:
oops.. it works that way for <input> fields, if you use <textarea> objects then you gota use innerText property instead of value
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.