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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Question regarding form validation

    Please look at my code:

    <SCRIPT>
    function validate()
    {
    ver3=addip.IP3.value;
    ver4=addip.IP4.value;
    vermac=addip.mac.value;

    if (!(ver3>=1 && ver3<=12))
    {
    alert('Valid 3rd Octet is 0-12');
    event.returnValue=false;
    }

    if (!(ver4>=31 && ver4<=210))
    {
    alert('Valid 4th Octet is 31-210');
    event.returnValue=false;
    }

    if (vermac=='')
    {
    alert('MAC Address is required');
    event.returnValue=false;
    }

    }
    </SCRIPT>

    If I substitute the number 0 to this line:
    if (!(ver3>=1 && ver3<=12))
    where it will be
    if (!(ver3>=0 && ver3<=12))

    the code doesn't work, please help me fix it tnx

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    It works fine for me when I test it. Why should it not work?

    <SCRIPT>
    function validate()
    {
    ver3=15;
    ver4=4;
    vermac='';

    if (!(ver3>=0 && ver3<=12))
    {
    alert('Valid 3rd Octet is 0-12');
    event.returnValue=false;
    }

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Ii woun't work as desired because the attribute's values return strings not numbers. And the objects are not referenced correctly. The root is document

    should have been

    ver3=Number(document.addip.IP3.value);
    ver4=Number(document.addip.IP4.value);
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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