onkeyup event not firing in firefox and chrome [Resolved]

Posted by Sahoo under JavaScript on 2/29/2012 | Points: 10 | Views : 10046 | Status : [Member] | Replies : 3
hi,

I have written code to check max no of characters entered to textbox like below
<textarea name="textarea" id="txtComments" rows="3" onkeyup='return maxLength(this,"250");' style="width: 940px" ></textarea>

in my js file I have written this function
//to check maximun length of comment
function maxLength(field, maxChars) {
if (field.value.length >= maxChars) {
event.returnValue = false;
var object = "-More than " + maxChars + " characters have been entered.";
errorAlert("error", "Maximum length error", object);
return false;
}

}

it is working fine in IE,but not in firefox and chrome.




Responses

Posted by: Blessyjees on: 2/29/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Try like this. This is working in FF, chrome and IE

 <textarea name="textarea" id="txtComments" rows="3" onkeyup='return fnMaxLength(this,"5");' style="width: 940px" ></textarea> 


function fnMaxLength(field, maxChars) {
if (field.value.length >= maxChars) {
var object = "-More than " + maxChars + " characters have been entered.";
//errorAlert("error", "Maximum length error", object);
alert(object);
return false;
}
}


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajkatie on: 2/29/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Kindly , refer below url. working fine in firefox,chrome and IE
http://www.javascriptkit.com/javatutors/javascriptkey2.shtml

Rajesh Patel
.Net Trainer(MSCD | MCT | MS)
Brainbench (Asp.Net 4.5 and C# 5.0)

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sahoo on: 2/29/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you very much for help.

Actually maxLength is a java script property so it was not working.

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response