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
https://forums.phpfreaks.com/topic/190773-enter-key-to-submit-form-in-textarea/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.