How to clear onChange?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Navarre

    How to clear onChange?

    Hello,

    I am doing form validation using 'onChange', so that every time a text
    input is entered and focus is lost on that text input, it will check to make
    sure it is an integer:

    function InputCheck(oThi s);
    if (isNaN(oThis.va lue) || (oThis.value.in dexOf('.') > 0))
    {
    alert('The Entered Code Number Must Be an INTEGER -- No Alpha or
    Special Characters Allowed.');
    oThis.value='';
    oThis.blur();
    oThis.focus();
    }

    The problem is that, say I type "hello" in the text input. It will give
    the alert and then clear the value in the text box, as it should. The
    problem is that if I type "hello" again a second time, it accepts it. It
    seems that even though I clear the value in the text box when the input
    isn't valid, 'onChange' doesn't know it is cleared and so entering the same
    thing a second time doesn't look like a change to it.
    As you can see in my function, I tried to blur() and focus() with the
    cleared value to try to force onChange to see the cleared value...
    So, how do you get around this problem?

    Thanks in advance,
    Scott Navarre


  • Padam Jain

    #2
    Re: How to clear onChange?

    "Scott Navarre" <smn@asus.net > wrote in message news:<bupilp01d 3h@enews4.newsg uy.com>...[color=blue]
    > Hello,
    >
    > I am doing form validation using 'onChange', so that every time a text
    > input is entered and focus is lost on that text input, it will check to make
    > sure it is an integer:
    >
    > function InputCheck(oThi s);
    > if (isNaN(oThis.va lue) || (oThis.value.in dexOf('.') > 0))
    > {
    > alert('The Entered Code Number Must Be an INTEGER -- No Alpha or
    > Special Characters Allowed.');
    > oThis.value='';
    > oThis.blur();
    > oThis.focus();
    > }
    >
    > The problem is that, say I type "hello" in the text input. It will give
    > the alert and then clear the value in the text box, as it should. The
    > problem is that if I type "hello" again a second time, it accepts it. It
    > seems that even though I clear the value in the text box when the input
    > isn't valid, 'onChange' doesn't know it is cleared and so entering the same
    > thing a second time doesn't look like a change to it.
    > As you can see in my function, I tried to blur() and focus() with the
    > cleared value to try to force onChange to see the cleared value...
    > So, how do you get around this problem?
    >
    > Thanks in advance,
    > Scott Navarre[/color]


    Hi
    If call this function 'onBlur' at the place of 'onFocus'
    u won't get this problem

    Padam

    Comment

    • Dr John Stockton

      #3
      Re: How to clear onChange?

      JRS: In article <bupilp01d3h@en ews4.newsguy.co m>, seen in
      news:comp.lang. javascript, Scott Navarre <smn@asus.net > posted at Thu,
      22 Jan 2004 15:24:47 :-
      [color=blue]
      > I am doing form validation using 'onChange', so that every time a text
      >input is entered and focus is lost on that text input, it will check to make
      >sure it is an integer:
      >
      > function InputCheck(oThi s);
      > if (isNaN(oThis.va lue) || (oThis.value.in dexOf('.') > 0))
      > {
      > alert('The Entered Code Number Must Be an INTEGER -- No Alpha or
      >Special Characters Allowed.');[/color]

      That will, I think, allow a negative integer, and also 3e-5 which is not
      an integer. It also accepts 0xFF, which you might not want.

      If you want all digits, or [optional] sign then only digits, test for
      that, using a RegExp. Don't assume that you can predict all possible
      breaches of a method such as yours.

      See <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...