?
Solved

requiring form input

Posted on 2000-03-26
5
Medium Priority
?
211 Views
Last Modified: 2010-04-09
I have a form with 20 check boxes and two text input boxes. One for email, the other for zip code. I would like to make it so that the email is required and if it isn't entered and the submit button is pushed a error window will pop up stating that their email address is required to proceed. How can I do that?

Thanks
0
Comment
Question by:timshank
[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
  • 4
5 Comments
 
LVL 3

Expert Comment

by:MHQ
ID: 2659228
This code should do the trick:

<HTML>
<HEAD>
<SCRIPT>
function submit_page(form) {

            // CHECKES IF THERE IS AN ADRESS
        if(form.theField.value == "") {
            alert("You left the Email field blank.");
            return false;
        }

        // CHECKS IF IT IS A VALID ADRESS
            if(form.theField.value.indexOf('@', 0) == -1) {
              alert("You did not enter a valid email address.");
                  return false;
        }
            form.submit();      
    }
</SCRIPT>
</HEAD>

<BODY>
<form action="thepagetosendto.html" name="theform">
<input type="text" name="theField">
<input type="button" value="SUBMIT" onClick="submit_page(this.form)">
</form>
</BODY>
</HTML>
0
 

Author Comment

by:timshank
ID: 2659476
The error window comes up, however after I click on the ok button it takes me away from the form page. How can I keep my visitors at the form page until they put their email address in?

Thanks
0
 
LVL 3

Expert Comment

by:MHQ
ID: 2661142
MHQ changed the proposed answer to a comment
0
 
LVL 3

Accepted Solution

by:
MHQ earned 150 total points
ID: 2661171
Sorry, that was a slight misstake by me. Try using this code instead:
It should work just as you want it to.

<HTML>
<HEAD>
<SCRIPT>
function submit_page(form) {
            check = true;
            // CHECKES IF THERE IS AN ADRESS
        if(form.theField.value.length < 1) {
            alert("You left the Email field blank.");
            check = false;
        }

        // CHECKS IF IT IS A VALID ADRESS
            if((check) && form.theField.value.indexOf('@', 0) == -1) {
              alert("You did not enter a valid email address.");
                  check = false;
        }
            if (check)
                  form.submit();
    }
</SCRIPT>
</HEAD>

<BODY>
<form action="to your next page" name="theform">
<input type="text" name="theField">
<input type="button" value="SUBMIT" onClick="submit_page(this.form);">
</form>
</BODY>
</HTML>

0
 
LVL 3

Expert Comment

by:MHQ
ID: 2676201
I'd appreciate if you could take time to evaluate my answer and if it's to your liking, award me the points.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Suggested Courses

752 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