SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast mca00's Avatar
    Join Date
    Aug 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Counting input value

    I've given up on doing this because it's made my eyes blurry. But here is the jist of it. I want to be able to count the value on a input box and if it is less then say 3 for example alert the user. Anyone know of a good script that works with 4+ broswers?
    Any help is appreciated.

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem - but what do you mean by "count"???!

    Is the input value changing automatically (ie. by another script),
    OR is the input changed by the user.

    IF the later is the case then:

    <input name="changing" id="changing" value=90 onchange="(this.value<4)?alert('DAMN boy - that is TOO low!'):null">

    That should do it... but i haven't tested it...

    Let me know if you need more - i'd be more than happy.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not sure what your after, but have a go with this

    PHP Code:

    <form>
      <
    input id="inputted" type="text" />
      <
    input id="inpBtn" type="button" value="submit" onclick="validation()" />
    </
    form>

    <
    script type="text/javascript"

      function 
    validation()
      {
        if (!
    isNaN(document.all.inputted.value) && document.all.inputted.value<=3alert(document.getElementById('inputted').value);
        else 
    alert('illegal num')
      }

    </script> 

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andrew - isn't that what i put

    Or are you covering something i didn't?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup i made sure the value was a number hehe

    ps, havent seen you about since i left for london lol.

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he he - i've been about.

    If you come to Gatwick - let me know - i live RIGHT
    next to it - we'll grab a pint!

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I should get into using "?" & ":" instead of if statements as i guess its faster

    PHP Code:

    <form>
      <
    input id="inputted" type="text" />
      <
    input id="inpBtn" type="button" value="submit" onclick="validation()" />
    </
    form>

    <
    script type="text/javascript"

      function 
    validation()
      {
        
    a=document.all.inputted;
        (!
    isNaN(a.value) && a.value<=&& a.value!='')? alert(a.value):alert('illegal num')
      }

    </script> 
    well I flew back to singapore a couple days ago to sort things out, if i keep on having these leaving party's and going down the pub everyday i'm gonna damage my liver even more lol. I went back for a week, and I ended up down the pub everyday with mates The doctors already said i'm an alcholic, I guess i'm proving him right so far

  8. #8
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol - sounds good though!

    Umm - it's actually the handle reference for the function i was avoiding - i sometimes consider them unneccessary.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  9. #9
    SitePoint Enthusiast mca00's Avatar
    Join Date
    Aug 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually Flawless that was what I was trying to do. Probably a better example of what I needed is like a phone number broken up into 3 boxes. Each box needs to caontain a certain number of digits in order to validate. But Flawless your code worked after I added length to it. Thanks for all the help.


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
  •