Forum Moderators: open

Message Too Old, No Replies

textarea in firefox

         

sumit123

9:19 am on Nov 11, 2005 (gmt 0)

10+ Year Member



i have made a form its workign fine with IE.
this form is have a textarea and when press entre it submits.textarea is having max limit and an alert is given there. in firefox when this alert comes and user press entre it fires onkeyup event in textarea.
hoz to stop it.
thanx in advance

Scally_Ally

11:22 am on Nov 11, 2005 (gmt 0)

10+ Year Member



can you post a little code to show us what might be happening?

sumit123

12:06 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



if(msg.length > chatMsgMaxLength)
{
chatarea.value = msg;
setCaretToPos(chatarea, chatMsgMaxLength, chatMsgMaxLength);
alert('Message length should not exceed the maximum limit of '+chatMsgMaxLength+' characters.');
chatarea.focus();
}

if msg crosses max limit alert will come. and if i press entre due to firefox event model it is captured in textarea and problem starts

var ctrl = e['ctrlKey'];
//alert(ctrl)
if((typeof e.keyCode!= "undefined")&&(e.keyCode == 13))
{//alert(1)
entr = true;
}
else
{//alert(2)
entr = (e.charCode == 13);
}

Scally_Ally

1:08 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



is firefox picking up your use of (e.charCode == 13); in the last part of your else statement?

Could you try something like

if((typeof e.keyCode!= "undefined")&&(e.keyCode == 13))
{//alert(1)
entr = true;
}
else
{//alert(2)
entr = false;
}

this would maybe then stop that enter (chr(13)) from being fired.

sumit123

1:32 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



:( it didnt work
when i press entre on alert, textarea also capture that event.it can be stopped by using stopPropagation() with object of alert which we cannt get.

sumit123

1:47 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



PS
it will go in if condition not else
thanx

rocknbil

6:25 pm on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var ctrl = e['ctrlKey'];

It's entirely possible Firefox is not seeing this? I recall the Moz's have a different way of reading keystrokes.

I was just doing this yesterday. It's got some picadillos (like if someone pastes a huge block in it will keep hammering them with messages every keyUp) but for direct entry it seems to work OK. Maybe it will get you thinking in a different direction:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
// You could pass any string to it from anywhere, really
function checkLen(str,len) {
if (str.length > len) { alert('The message field is only allowed 255 characters.'); return 0; }
}
// just added for this example
function chkForm(form) {
var txt = form.message.value;
var err = checkLen(txt,255);
if (err!= 0) { alert(err); form.submit(); }
}
</script>
</head>

<body>
<form method="post" action="whatever.pl" onSubmit="return false;">
<textarea name="message" rows="3" cols="45" onKeyUp="checkLen(this.value,255);"></textarea><br>
<input type="submit" onClick="chkForm(this.form);" value="submit">
</form>
</body>
</html>

sumit123

1:21 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



Hi,
even this example is creating same problem for me on firefox. if i press enter on alert it keep on coming.
thanx

natty

2:39 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



dont knwo if this will help,
but i have a similar type of thing on a text area on one of my sites..
but i just put a function on
<textarea onkeyup="textAreaCounter(this);" onkeydown="textAreaCounter(this);"> ....

which checks for the length as each char is entered, and will pop up a message when you reach the limit, and crop whatever is too long..

i realise you seem to want to be able to let the user press enter on the textarea to submit it..?
which might be confusing for the average schmo, as i dont think its the default behaviour..
anyhoo, i think maybe you need to add, as i have on keyup and down.. dunno


function textAreaCounter(t){
var textLength = t.value.length;
var counterInput = document.getElementById("counter");
if(textLength > 500){
alert("Sorry, the maximum length of comments is 500 characters");
t.value=t.value.substring(0,500);
}
counterInput.value = (500-parseInt(t.value.length));
}

not saying its perfect. but as far as i know it works for IE,FF,safari ..
- the counterInput is just a little text field that lets you know how may chars you have left as you type..
hth

sumit123

1:11 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Hi ,
can u give me implementation for key up and press?