Cheers Bobby, I figured it was to do with changing via script.

Just as a change to the solution I said I was going to use, the check should
have been:

obj.value.search(/[^0-9]/g, "") != -1

Adrian

-----Original Message-----
From: Bobby Hartsfield [mailto:[EMAIL PROTECTED]
Sent: 28 February 2006 20:56
To: CF-Talk
Subject: RE: OT JS onChange/onKeyUp Event Issue


Change 'onchange' to 'onblur' what appears to be happening is that the value
of the field is changed with the regex then when it hits the change()
function... it really hasn’t changed... since it was last changed by the
regex. Make sense?

...:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com



-----Original Message-----
From: Adrian Lynch [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 28, 2006 2:52 PM
To: CF-Talk
Subject: OT JS onChange/onKeyUp Event Issue

Can anyone shed some light on this?

I have a text field, in this I only want the user to type numbers, so
onkeyup runs a RegEx to remove a char if it's not a number.

I also want to detect if the field has changed(I'm not bothered if it
changes back to the original at the moment).

So I have the following as a simplified test:


<script type="text/javascript">

        function changed() {
                document.getElementById("output").innerHTML +=
"<p>CHANGED</p>";
        }

        function keyUpped(obj) {
                //obj.value = obj.value.replace(/[^0-9]/g, "");
                document.getElementById("output").innerHTML += "<p>KEY
UP</p>";
        }

</script>

<form>
        <input type="text" name="temp" onchange="changed();"
onkeyup="keyUpped(this);" />
</form>

<div id="output"></div>


If I type in the text field, onkeyup is fired and the output displays 'KEY
UP'. If I click out of the text field, onchange is fired and the output
shows 'CHANGED'.

If I comment back in the RegEx so it validates the input and changes it if
needed, it seems like the change is never detected when I click out of the
text field.

Any thoughts or ideas?



Adrian Lynch
http://www.halestorm.co.uk/

Spring clean out:
http://www.adrianlynch.co.uk/selling/


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:233682
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to