Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Events in Firefox

Status
Not open for further replies.

irida

Programmer
Sep 29, 2006
10
UA
Hello all!
I have a problem. When I'm writing a script to validate maxlength in the textarea element, I use event.returnValue=false (or just return false).
But it works only in IE. How should I change it to work in Mozila\firefox or any other browser.
Thanks a lot!
 
"Event" is an IE-only property. To be cross-browser, you need to pick up on the event data passed implicitly into your event handler.

Can you show the code you've got (HTML & JS)? It'd be easier to retrofit that way.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks!

function guardMaxLength(ta)
{
//check length after each time the key is pressed
maxlength=parseInt(ta.maxlength,10);
if(ta.value.length>=maxlength)
{

event.returnValue=false;
}
ta.value=value;
}
function ensureMaxLength(ta)
{
//check length before pasting
if(window.event.propertyName=='value')
{
ta=window.event.srcElement;
if(ta.value.length>ta.maxlength) {
ta.value=ta.value.substr(0,ta.maxlength);
}

}
}

<textarea maxlength="10" onkeypress="return guardMaxLength(this)" onpropertychange="return ensureMaxLength(this)">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top