help: text area event(Unsolved)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

help: text area event(Unsolved)

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

onkeypress would be the event you're talking about..

as for styling the buttons, it's all done with CSS.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you just told javascript to execute a string, which does nothing.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..)
Post Reply