Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51 03' -78" N -114 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    useing javascript check to check document

    I have 6 field boxes and i want if the first three are the same as the second three and then check box is marked that it brings up an alert but if the checkbox is marked and the second three are blank it continues I have the following

    {
    if(document.mailform.Night_Phone_Same_As_Day.checked == true)
    {
    if (document.mailform.night_phone_a.value == "" | document.mailform.night_phone_b.value == "" | document.mailform.night_phone_c.value == ""){return true;}
    else if (document.mailform.night_phone_a.value != document.mailform.day_phone_a.value | document.mailform.night_phone_b.value != document.mailform.day_phone_b.value | document.mailform.night_phone_c.value != document.mailform.day_phone_c.value)
    {
    alert("Please Dont Check the box if Night phone is different then day!")
    return
    }
    }}
    Where the return true; is is what I dont know what to put to tell it to ignore the else if and continue

    Thanks in advance

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont think your problem is difficult im just not sure what it is?

    You have a check box to say night phone i same as day
    to save the user entering the same data twice
    there are 3 possible phone numbers a, b, c for day and 3 for night..

    so if all the nights are blank and the user checks SAME checkbox
    then return true

    if all nights have been filled in and are same and user checks SAME checkbox
    then return true

    else if user checks SAME and a day != a night ,,b,,c then alert

    is that it?
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51 03' -78" N -114 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually I was able to figure it out all I had to do was tell it this

    {
    if(document.mailform.Night_Phone_Same_As_Day.checked == true)
    {
    if (document.mailform.night_phone_a.value == "" | document.mailform.night_phone_b.value == "" | document.mailform.night_phone_c.value == "")
    {
    (document.mailform.night_phone_a.value == document.mailform.day_phone_a.value | document.mailform.night_phone_b.value == document.mailform.day_phone_b.value | document.mailform.night_phone_c.value == document.mailform.day_phone_c.value)
    }
    else if (document.mailform.night_phone_a.value != document.mailform.day_phone_a.value | document.mailform.night_phone_b.value != document.mailform.day_phone_b.value | document.mailform.night_phone_c.value != document.mailform.day_phone_c.value)
    {
    alert("Please Dont Check the box if Night phone is different then day!")
    return
    }}
    that way when it was blank then the one is forwarded with the other! It makes sence but just hard to explain!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might like to add this line
    ....
    ....
    {
    document.mailform.Night_Phone_Same_As_Day.checked = false;
    alert("Please Dont Check the box if Night phone is different then day!")
    return
    }....
    ...
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I bet if you post your 3 form fields, and your function, I can shorten (or improve) it considerably, at least if you're only dealing with US and Canadian phone numbers...

    Just a tip to shorten your script (wow, that sounds like Dr. Suess!):

    If you're using something like document.mailform.
    over and over again, set it to a variable, such as:

    var f = document.mailform;

    From that point on, you can say stuff like:

    if (f.night_phone_a.value == "" | f.night_phone_b.value == "" | f.night_phone_c.value == "") {

    instead of the really lengthy code you have.

    Alternatively (and even better), you can just use (f) in the function parameter, and pass (this) from the form tag using onsubmit. What that does, is passes the form object to the function parameter "f" right when you're calling the function - that way the function always knows that "f" is the form that called the function... get it? If not, here's an example that might clarify what I mean, since sometimes I'm better at explaining with code:

    Code:
    <html>
    <head>
       <title>Example</title>
    <script type="text/javascript">
    <!--
    function alertFormName(f) {
       alert(f.name + f.punctuation.value);
       return false;
    }
    // -->
    </script>
    </head>
    <body>
       <form name="Yay" action="javascript://" onsubmit="alertFormName(this)">
          <input type="hidden" name="punctuation" value="!!!" />
          <input type="submit" value="Submit" />
       </form>
    </body>
    </html>
    Also, I'd rather allow people to type a phone number all in one field, and then validate the phone number against a regular expression, rather than having to deal with three separate fields for each phone number.
    Last edited by whammy; 01-23-2003 at 12:25 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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