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

    Join Date
    Sep 2002
    Posts
    21
    Rep Power
    0

    Problem: Javascript functions


    I'm writing a function with javascript. when user enter a value, and then display a message. I know it's wrong, cuz i don't know how to do "between" in javascript. I hope anyone can corrct it for me. Also, I want to know if there's better way to write this function. e.g. switch(num)?

    The problem is like this:

    <script language="javascript" type="text/javascript">
    <!--//
    function DisNum()
    {
    var num=document.form1.num.value;
    if (num=<= 0 || num =>20)
    {
    alert ("Chidren");
    }
    if (num=<= 21 || num =>40)
    {
    alert ("Adult");
    }

    if (num=<= 41 || num =>60)
    {
    alert ("ok...");
    }
    }
    //-->
    </script>
    Last edited by Tozilla; September 4th, 2002 at 08:07 AM.
  2. #2
  3. Corporate Stooge
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Aberdeen, Scotland
    Posts
    134
    Rep Power
    14
    You can do between using && such as:

    if (num >= 0 && num <= 20)
    {
    alert ("Chidren");
    }
    Never sign your code....it leaves you liable!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    21
    Rep Power
    0
    thanks for helping

IMN logo majestic logo threadwatch logo seochat tools logo