edoyuk
asked on
onchange and onkeyup together.
Hi,
I wrote a validation function,which makes for example 1234567 ---> 1,234,567
I use it in a textbox and I wanna also use onchange event for the same textbox. The function I wrote runs when unkeyUp activated.
However unkeyUp and onchange events doesn't work together?
Do u have any idea?
My function:
function Fcm2(thisis) {
var tempstr,newstr,str,i,str2 ;
var commapos,aftercomma,commac ount;
i=0;
str = thisis.value;
if (str.indexOf(".") < 0) {
while ( 15 > i) { str = str.replace(",",""); i=i+1; }
commacount=0;
commapos=str.indexOf(";");
if (commapos>=0) { aftercomma=str.substr(comm apos); str=str.substr(0,commapos) ; }
else aftercomma="";
if (str.length > 3) {
tempstr=str;
newstr="";
while (tempstr.length > 3)
{ newstr=","+tempstr.substr( tempstr.le ngth-3)+ne wstr;
tempstr=tempstr.substr(0,t empstr.len gth-3); }
thisis.value = tempstr+newstr+aftercomma;
}
}
return true;
}
---------------------
function calcul(thh){
alert("change");
}
function press(thisis){
if(window.event.keyCode < 47 && window.event.keyCode > 57) { window.event.keyCode = 9008999; }
if(window.event.keyCode == 9008999) {return false; } else {Fcm(thisis) }
}
---------------------
<td width=80% height=20><input value="" class=numstd onchange="calcul(this)" onkeyUp="press(this)" name=deneme size=40 maxlength=40></td>
I wrote a validation function,which makes for example 1234567 ---> 1,234,567
I use it in a textbox and I wanna also use onchange event for the same textbox. The function I wrote runs when unkeyUp activated.
However unkeyUp and onchange events doesn't work together?
Do u have any idea?
My function:
function Fcm2(thisis) {
var tempstr,newstr,str,i,str2 ;
var commapos,aftercomma,commac
i=0;
str = thisis.value;
if (str.indexOf(".") < 0) {
while ( 15 > i) { str = str.replace(",",""); i=i+1; }
commacount=0;
commapos=str.indexOf(";");
if (commapos>=0) { aftercomma=str.substr(comm
else aftercomma="";
if (str.length > 3) {
tempstr=str;
newstr="";
while (tempstr.length > 3)
{ newstr=","+tempstr.substr(
tempstr=tempstr.substr(0,t
thisis.value = tempstr+newstr+aftercomma;
}
}
return true;
}
---------------------
function calcul(thh){
alert("change");
}
function press(thisis){
if(window.event.keyCode < 47 && window.event.keyCode > 57) { window.event.keyCode = 9008999; }
if(window.event.keyCode == 9008999) {return false; } else {Fcm(thisis) }
}
---------------------
<td width=80% height=20><input value="" class=numstd onchange="calcul(this)" onkeyUp="press(this)" name=deneme size=40 maxlength=40></td>
ASKER
No alambres with this method it goes to database every time a key is pressed!!!
This is not that I want to.
This is not that I want to.
what do you want then? I don't get your aim
ASKER
With onkeyup I want to use my validate function but onchange doesnt work when I use it.
this is then:
<HTML>
<HEAD>
<TITLE></TITLE>
<script type="text/javascript">
function Fcm(thisis)
{
var tempstr,newstr,str,i,str2 ;
var commapos,aftercomma,commac ount;
i=0;
str = thisis.value;
if (str.indexOf(".") < 0) {
while ( 15 > i) { str = str.replace(",",""); i=i+1; }
commacount=0;
commapos=str.indexOf(";");
if (commapos>=0) { aftercomma=str.substr(comm apos); str=str.substr(0,commapos) ; }
else aftercomma="";
if (str.length > 3) {
tempstr=str;
newstr="";
while (tempstr.length > 3)
{ newstr=","+tempstr.substr( tempstr.le ngth-3)+ne wstr;
tempstr=tempstr.substr(0,t empstr.len gth-3); }
thisis.value = tempstr+newstr+aftercomma;
}
}
return true;
}
function calcul(thh){
if (thh.value != thh.oldValue) alert("change");
thh.oldValue = thh.value;
}
function press(thisis){
if(window.event.keyCode < 47 && window.event.keyCode > 57) { window.event.keyCode = 9008999; }
if(window.event.keyCode == 9008999) {return false; } else {Fcm(thisis) }
}
</script>
</HEAD>
<BODY>
<input value="" class=numstd onblur="calcul(this)" onkeyUp="press(this)" name=deneme size=40 maxlength=40>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE></TITLE>
<script type="text/javascript">
function Fcm(thisis)
{
var tempstr,newstr,str,i,str2 ;
var commapos,aftercomma,commac
i=0;
str = thisis.value;
if (str.indexOf(".") < 0) {
while ( 15 > i) { str = str.replace(",",""); i=i+1; }
commacount=0;
commapos=str.indexOf(";");
if (commapos>=0) { aftercomma=str.substr(comm
else aftercomma="";
if (str.length > 3) {
tempstr=str;
newstr="";
while (tempstr.length > 3)
{ newstr=","+tempstr.substr(
tempstr=tempstr.substr(0,t
thisis.value = tempstr+newstr+aftercomma;
}
}
return true;
}
function calcul(thh){
if (thh.value != thh.oldValue) alert("change");
thh.oldValue = thh.value;
}
function press(thisis){
if(window.event.keyCode < 47 && window.event.keyCode > 57) { window.event.keyCode = 9008999; }
if(window.event.keyCode == 9008999) {return false; } else {Fcm(thisis) }
}
</script>
</HEAD>
<BODY>
<input value="" class=numstd onblur="calcul(this)" onkeyUp="press(this)" name=deneme size=40 maxlength=40>
</BODY>
</HTML>
ASKER
Simply,
I want to use both validation and onchange event?
If you write 1234567 to the textbox it will make it 1,234,567 every time you write a number and then if you press tab button it will save it to the database?
Do you have a solution for that?
Thank you....
I want to use both validation and onchange event?
If you write 1234567 to the textbox it will make it 1,234,567 every time you write a number and then if you press tab button it will save it to the database?
Do you have a solution for that?
Thank you....
ASKER
alambres,
It is nor efficient to use onBlur because I wanna do some savings when data is changed in the textbox...
It is nor efficient to use onBlur because I wanna do some savings when data is changed in the textbox...
what do you understand by "data is changed"? I repeat: onchange event triggers when EXITING (=ONBLUR) the field. You should check if the value's changed when blur. Otherwise, you'll be doing the saving to DB every keyPress, which you said you don't want to. So?
ASKER
BUT how can I check easily(without global variables) if the value's changed when blur?
You kill the onChange event by changing the field value by previous events.
So you have to check for changes on your own.
Like this:
<input type=text value="" onFocus="this.oldValue=thi s.value" onBlur="if(this.value!=thi s.oldValue )alert('ch anged')">
Good luck,
NetGroove
So you have to check for changes on your own.
Like this:
<input type=text value="" onFocus="this.oldValue=thi
Good luck,
NetGroove
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: alambres {http:#9626560}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: alambres {http:#9626560}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
something like that:
function calcul(thh){
if (thh.value != thh.oldValue) alert("change");
thh.oldValue = thh.value;
}
<td width=80% height=20><input value="" class=numstd onkeyUp="press(this);calcu
hope it helps ya.
peace
alambres