Page 1 of 1

help: text area event(Unsolved)

Posted: Sun Aug 14, 2005 1:55 pm
by raghavan20
I have got a text area input control.
I want to know the name of the event when an user hits enter inside the textarea.
Anybody can tell me how to submit a form and clear the contents in the text area when the user hits 'enter' inside the textarea.
Is it possible to format the <input type='submit'> button; add some style to it? I dont want images that change on mouseover and mouseout rather pure html submit buttons like the ones like preview and submit buttons in this forum?

Code: Select all

<form name = 'frmChatMessage'  method = 'get'>
<text area></textarea>
</form>

Posted: Sun Aug 14, 2005 7:08 pm
by feyd
onkeypress would be the event you're talking about..

as for styling the buttons, it's all done with CSS.

Posted: Mon Aug 15, 2005 6:12 am
by raghavan20
This does not work ...why???

Code: Select all

<html>
<head>
<script language = 'javascript'>
	function processTextArea(value){
		frmChatMessage.submit();//submit the form
		frmChatMessage.taMessage.value = "";//reset the text area field
		
	}
</script>
</head>
<body>
<table>
	<form name = 'frmChatMessage' method = 'get' action = ''>			
	<tr><td><textarea id = 'taMessage' name = 'taMessage' rows = '2' cols = '45' onkeypress= 'javascript:"processTextArea(this.value);"'><chat message></textarea></td>
	<td><input type = 'submit' id = 'subMessage' name = 'subMessage' value = 'Send' ></td></tr>
	</form>
</table>
</body>
</html>

Posted: Mon Aug 15, 2005 6:32 am
by feyd
you just told javascript to execute a string, which does nothing.

Posted: Mon Aug 15, 2005 6:35 am
by raghavan20
Actually, I dont want to use the value in the text area.
I simply passed that value to the function,,pls ignore it.

I will give you the whole situation so you can help me better.
I have a textarea for the chat user to type in. I dont expect him to click on the send button rather if he hits 'enter' on the keyboard the form should submit and the content in the text area should be cleared.

Posted: Mon Aug 15, 2005 7:31 am
by feyd
you may want to look up some tutorials on how onkeypress works. The event is already in Javascript, so telling Javascript it's going to run Javascript is kinda... silly. You'll also find out that any keys being pressed inside the textarea will fire the event. You must filter it down to the characters you want to look for (there are multiple keycodes for "enter" depending on encodings, among other things..)