Jump to content

enter key to submit form in textarea


Alicia

Recommended Posts

Hi,

 

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?

 


<script>
function handleEnter(e)
{
var characterCode;
if(e && e.which)
{
	e = e;
	characterCode = e.which;
} 
else 
{
	e = event;
	characterCode = e.keyCode;
}

if(characterCode == 13)
{
	document.forms["myform"].submit();
	return false;
} 
else
{
	return true;
}
}
</script>

<form id="myform" action="submit-form.php" method="get">
  <p>Search:
  <input type='textarea' name='query'>
  </p>
  <p>
    <label>
      <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.