?
Solved

web textbox validation

Posted on 2005-03-11
7
Medium Priority
?
841 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:bear23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 13522936
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
 
LVL 7

Expert Comment

by:dttri
ID: 13523133
 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
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 200 total points
ID: 13523291
<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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:guru_k
ID: 13523663
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
 
LVL 1

Expert Comment

by:neu-rah
ID: 13547129
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
 
LVL 1

Expert Comment

by:neu-rah
ID: 13547160
oops.. it works that way for <input> fields, if you use <textarea> objects then you gota use innerText property instead of value
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question