Can I set a watch on a textarea? If so, how?

31 views
Skip to first unread message

dfh...@gmail.com

unread,
May 22, 2014, 12:11:17 PM5/22/14
to fir...@googlegroups.com
I have a textarea where the user enters the answer to a question. If he enters the wrong answer, or no answer (just hits the enter key), the script clears the textarea.  When it clears the textarea, I end up with a new line that I don't want.  I want to set a watch on the textarea so I can find out where that new line is coming from.

Is there a better way to track down this problem?

Thanks, Dan H

Farshid Beheshti

unread,
May 22, 2014, 4:03:09 PM5/22/14
to fir...@googlegroups.com

I have a textarea where the user enters the answer to a question. If he enters the wrong answer, or no answer (just hits the enter key), the script clears the textarea.  When it clears the textarea, I end up with a new line that I don't want.
 
I think you don't need to do anything with Firebug. Add event.preventDefault(); at the end of the function handling the event when a return key is pressed, something like this:

textarea.click = function(event){
if(event.keyCode == 13){
event.preventDefault();
}
}
Note |event| is the name of the argument.

Although the answer doesn't relate to the Firebug, but just as way to fix the issue.

Farshid


--
You received this message because you are subscribed to the Google Groups "Firebug" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebug+u...@googlegroups.com.
To post to this group, send email to fir...@googlegroups.com.
Visit this group at http://groups.google.com/group/firebug.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebug/5bffeedf-a296-44df-a64c-ef349379e081%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Zartner

unread,
May 22, 2014, 6:11:33 PM5/22/14
to fir...@googlegroups.com
You may want to set a breakpoint within the event handler for the textarea to track down where the new line comes from. Though it sounds like the new line comes from hitting Enter within the textarea.
As Farshid mentioned you can prevent the default behavior (i.e. entering a new line) when hitting Enter using event.preventDefault(), though his code has a little flaw as it's not the click event you need to react to but the keydown event. So the code would actually look something like this (with some other improvements):

textarea.addEventListener("keydown", function(event) {
  if (event.keyCode === KeyEvent.DOM_VK_RETURN) {
    event.target.value = "";
    event.preventDefault();
  }
});


Sebastian


On Thursday, May 22, 2014 10:03:09 PM UTC+2, Farshid Beheshti wrote:

I have a textarea where the user enters the answer to a question. If he enters the wrong answer, or no answer (just hits the enter key), the script clears the textarea.  When it clears the textarea, I end up with a new line that I don't want.
 
I think you don't need to do anything with Firebug. Add event.preventDefault(); at the end of the function handling the event when a return key is pressed, something like this:

textarea.click = function(event){
if(event.keyCode == 13){
event.preventDefault();
}
}
Note |event| is the name of the argument.

Although the answer doesn't relate to the Firebug, but just as way to fix the issue.

Farshid

--
You received this message because you are subscribed to the Google Groups "Firebug" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebug+unsubscribe@googlegroups.com.

Farshid Beheshti

unread,
May 23, 2014, 8:16:38 AM5/23/14
to fir...@googlegroups.com
though his code has a little flaw as it's not the click event you need to react to but the keydown event.    
Ah, Yes! Since I was in hurry :-)

Farshid

Reply all
Reply to author
Forward
0 new messages