SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Alert message if empty value???

    My code for this is below:
    Question:
    I have a form button...onclick it does function validate...
    if agree1 and question 1 are empty it should alert the message...
    else it should do check.
    However, during my testing it's not doing the alert if these strings
    are empty.

    Are my empty strings correct?

    =====================================

    <script language="javascript">

    function validate(){

    //Declare Variables
    agree1 = document.form.agree1.checked;
    agree2 = document.form.agree2.checked;
    agree3 = document.form.agree3.checked;
    agree4 = document.form.agree4.checked;
    question1 = document.form.question1.checked;

    if((agree1 == ' ') && (question1 == ' '))
    {
    alert("sucks");
    }
    else
    {
    check();
    }
    }


    function check(){

    //Declare Variables
    agree1 = document.form.agree1.checked;
    agree2 = document.form.agree2.checked;
    agree3 = document.form.agree3.checked;
    agree4 = document.form.agree4.checked;

    if((agree1==true) && (agree2==true) && (agree3==true) && (agree4==true))
    {
    window.document.location.href = "index_return.htm";
    }
    else
    {
    window.document.location.href="x/x.htm";
    }

    }


    </script>

  2. #2
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It appears that agree 1 and question1 are checkboxes. I can't remember for sure but you might try to check to see if agree1 and question1 are false like you do in function Check(). This should display the alert if it is false.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I got it.. thanks for the lead...

    if(!agree1 && !question1 && !question2 && !question3)

    I used the logical operators to say if agree1 is not true....this validates the form correctly..

    This article helped a lot:
    http://www.webmasterbase.com/article.php?pid=44&aid=455


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •