#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    240
    Rep Power
    16

    Simple Alert Box question


    Hey I have a really simple question. I dont know javascript and I have been looking for something like this forever.

    Is there a way to right something simple like if the form field is empty then pop up an alert box saying it was empty if not go on and do the normal action of the script like something onsubmit but i dont know any of the code. I tried using a couple of premade scripts but they only display the first alert box and it moves on anyway. I was using the same script on a diff website and I didnt have that problem. I figured it would be easier to write something simple like this then go through 1000 lines of code.
    Can someone just help me out with a simple if statment that should work right??? Please help Im desparate. Thanks

    So this is kinda what i want

    if (fielname == "")
    {

    echo "you left out fieldname";

    }

    if (fieldname2)

    {

    echo "you left out fieldname";

    }

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2003
    Posts
    1,037
    Rep Power
    31
    Code:
    function validate(){
      if(document.formName.elementName.value == ""){
        alert("Your message");
        return false;
      }
      // Whatever
      return true;
    }
    And in your onsubmit:

    Code:
    onsumbit="return !validate()"
    I'd suggest you read a few simple Javascript tutorials if you want to to anymore Javascript though.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    240
    Rep Power
    16
    Im gonna try it out but that looks perfect. Thanks
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    240
    Rep Power
    16
    [PHPNET=""]Thats wierd it doesnt work.

    I put this in my head

    <script language="JavaScript" type="text/javascript">


    function validate(){
    if(document.auto_insurance_validation.first_name.value == ""){
    alert("First Name is empty");
    return false;
    }
    // Whatever
    return true;
    }


    </script>



    and this is my form field

    <form NAME="auto_insurance_validation" onsumbit="return !validate()" ACTION="auto_insurance_2.php" METHOD="POST">

    <input id="first_name" name="first_name">

    </form> Thanks[/PHPNET]
  8. #5
  9. Professional Lay-A-Bout
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Location
    Ann Arbor, Michigan
    Posts
    302
    Rep Power
    16
    Originally Posted by sgreeny12
    [PHPNET=""]Thats wierd it doesnt work.

    I put this in my head

    <script language="JavaScript" type="text/javascript">


    function validate(){
    if(document.auto_insurance_validation.first_name.value == ""){
    alert("First Name is empty");
    return false;
    }
    // Whatever
    return true;
    }


    </script>



    and this is my form field

    <form NAME="auto_insurance_validation" onsumbit="return !validate()" ACTION="auto_insurance_2.php" METHOD="POST">

    <input id="first_name" name="first_name">

    </form> Thanks[/PHPNET]
    Hey!... Is this spelled that way in your code: onsumbit

    Double Hey- where is your submit button?

    Comments on this post

    • medialint agrees : Incredibly 90% of errors are typos and misspellings. Fortunately many people proof their code *first* for such things before going off to search for a holy grail of debugging enlightenment
    Last edited by trumley; August 31st, 2005 at 10:00 AM.
    Thomas

    Dogs and computers both do everything you tell them.
    But computers don't like their tummies rubbed.
  10. #6
  11. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Dec 2003
    Posts
    2,343
    Rep Power
    583
    triple hey- shouldn't the code be:
    Code:
    return validate()
    instead of
    Code:
    return !validate()
    based on that function?

IMN logo majestic logo threadwatch logo seochat tools logo