|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
JavaScript - Keypress function not working in mozilla
hi,
i got problem. my onKeyPress function work in IE but not in mozilla.. below is some my coding <SCRIPT LANGUAGE="JavaScript"> function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) // if too long...trim it! field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter else countfield.value = maxlimit - field.value.length; } function ValidateNumeric(ev) { var keyCode = window.event.keyCode; if ((ev.keyCode > 127 || ev.keyCode < 95) && (ev.keyCode > 93 || ev.keyCode < 65) && (ev.keyCode > 63 || ev.keyCode < 43) && (ev.keyCode > 41 || ev.keyCode < 40) && (ev.keyCode > 37 || ev.keyCode < 37) && (ev.keyCode > 32 || ev.keyCode < 1)) window.event.returnValue = false; } </SCRIPT> <TEXTAREA id=textarea1 onkeydown="javascript:textCounter(this.form.komen,this.form.r emLen,500);" onkeyup="javascript:textCounter(this.form.komen,this.form.r emLen,500);" onKeyPress="ValidateNumeric(event)" style="WIDTH: 460px; HEIGHT: 195px" name=komen cols=49 rows=2 class=test></TEXTAREA> can anyone help me how to solve this matter..or maybe anyone face same problem, can give opinion how to settle down this problem...plz.. thanks in advance... |
|
#2
|
||||
|
||||
|
hi
welcome to aspfree... ![]() please put your code in the code tags or you can select your code part and click on the # button in the editor.. Code:
your code goes here....... that would help you get a quicker response....
__________________
“Life may not be the party we hoped for, but while we are here we should sing, dance and be merry all the time....... "
|
|
#3
|
||||
|
||||
|
I think you'd be better off scrapping the event listening, and use
something simpler like a RegEx to make sure no non-numeric values get entered...
__________________
Support requests via PM will be ignored! |
|
#4
|
|||
|
|||
|
hi aashishnakra....
sorry coz not do in proper.. here is my code Code:
<SCRIPT LANGUAGE="JavaScript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
function ValidateNumeric(ev)
{
var keyCode = window.event.keyCode;
if ((ev.keyCode > 127 || ev.keyCode < 95) && (ev.keyCode > 93 || ev.keyCode < 65) && (ev.keyCode > 63 || ev.keyCode < 43) && (ev.keyCode > 41 || ev.keyCode < 40) && (ev.keyCode > 37 || ev.keyCode < 37) && (ev.keyCode > 32 || ev.keyCode < 1))
window.event.returnValue = false;
}
</SCRIPT>
<TEXTAREA id=textarea1 onkeydown="javascript:textCounter(this.form.komen,this.form.r emLen,500);" onkeyup="javascript:textCounter(this.form.komen,this.form.r emLen,500);" onKeyPress="ValidateNumeric(event)" style="WIDTH: 460px; HEIGHT: 195px" name=komen cols=49 rows=2 class=test></TEXTAREA>
|
|
#5
|
|||
|
|||
|
onkeypress function works in mozilla. There are some other things that you need to fix in your code.
1) window.event does not work in firefox. Hence modify ValidateNumeric function as below. if(window.event) keyPressed = window.event.keyCode; //for IE else keyPressed = e.which; // others Use keyPressed variable in your if condition to compare. 2) In the textarea html, there are spaces in between which is not allowed. Correct it. I think i should be the name of the field where you want to show the count. javascript:textCounter(this.form.komen,this.form.r emLen,500); |
|
#6
|
|||
|
|||
|
Also use
e.preventDefault();instead of window.event.returnValue = false; |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > JavaScript - Keypress function not working in mozilla |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|