I wanted to replace the textfield in the script below to textarea but then the javascript function will stop working. How can I make the textarea works as the textfield when the enter key is pressed ? Please advise. or is there any way i can increase the lines of the textfield?
There is no such thing as <input type='textarea'>!
Do you mean a <textarea> element? If so, overriding the Enter key would be a very bad idea, because it would make it difficult or impossible to create a line break in the textarea. It would most likely annoy users, too, since it’s a non-standard behaviour.
If you mean a text field (<input type="text">) then Enter already works as submit. Except in IE, if there’s just one field. The workaround is to add a hidden field (<input type="hidden" value="foo">).
It’s also very odd that you wrap your submit button in a <label>, yet you do not mark up the real label (‘Search:’) as a <label>.
actually what i want is to show more than one line from the text field and i dont really care about the line break.,… anyway i can make this enter key to submit form happen ?
But if users can’t input a line break, there won’t be more than one line in the textarea (a text field is single-line).
If you really want to do this, you’ll need to add a keyboard event handler for the textarea, check for Enter keys and call the form’s submit() method. Exactly how to do this varies somewhat between browsers, unfortunately.