473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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(oThis);
if (isNaN(oThis.value) || (oThis.value.indexOf('.') > 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
Jul 20 '05 #1
2 6352
"Scott Navarre" <sm*@asus.net> wrote in message news:<bu*********@enews4.newsguy.com>...
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(oThis);
if (isNaN(oThis.value) || (oThis.value.indexOf('.') > 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

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

Padam
Jul 20 '05 #2
JRS: In article <bu*********@enews4.newsguy.com>, seen in
news:comp.lang.javascript, Scott Navarre <sm*@asus.net> posted at Thu,
22 Jan 2004 15:24:47 :-
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(oThis);
if (isNaN(oThis.value) || (oThis.value.indexOf('.') > 0))
{
alert('The Entered Code Number Must Be an INTEGER -- No Alpha or
Special Characters Allowed.');


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.demon.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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
1
by: Christoph | last post by:
I'm trying to validate some HTML form elements when the user tabs out of each element. However, I'm having some problems. It appears that the order of events is onChange followed some time...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
5
by: Good Man | last post by:
Hi there I'm adding form fields on the fly with some javascript DOM programming. I basically just clone a hidden <div>, then adjust node properties to make this new <div> have unique values...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
3
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.