Author Topic: submit form on enter button  (Read 1134 times)

0 Members and 1 Guest are viewing this topic.

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
submit form on enter button
« on: March 12, 2010, 05:59:51 PM »
How can I submit a form using the enter key on the keyboard?
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: submit form on enter button
« Reply #1 on: March 12, 2010, 06:24:32 PM »
1: Fill in Form
2: Press enter
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: submit form on enter button
« Reply #2 on: March 12, 2010, 06:43:14 PM »
Considering the enter key only does new lines and doesn't submit the form. Quite impossible.

Oh and I just noticed, this is the wrong place for this post >.< Sorry
« Last Edit: March 12, 2010, 06:46:02 PM by TeddyKiller »
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: submit form on enter button
« Reply #3 on: March 12, 2010, 06:46:00 PM »
Quote
Considering the enter key only does new lines and doesn't submit the form. Quite impossible.

You'll need to tab out of whatever box your typing in obviously.

Offline cags

  • Guru
  • Fanatic
  • *
  • Posts: 3,250
  • Gender: Male
    • View Profile
    • TiB Studios
Re: submit form on enter button
« Reply #4 on: March 12, 2010, 06:46:38 PM »
Attach a JavaScript keydown event, if the key is enter submit the form. This isn't possible with PHP as it is client side.
CodeCanyon - Cheap, High Quality, Ready Made Scripts.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: submit form on enter button
« Reply #5 on: March 12, 2010, 06:47:05 PM »
only if your typeing in a textarea

Also:
PHP doesnt actually have forms. Try htmlfreaks.com
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: submit form on enter button
« Reply #6 on: March 12, 2010, 06:51:44 PM »
Quote
Considering the enter key only does new lines and doesn't submit the form. Quite impossible.

You'll need to tab out of whatever box your typing in obviously.

Well yeah, but how would you do it just by clicking enter? I've tried all methods and they dont actually work.

Attach a JavaScript keydown event, if the key is enter submit the form. This isn't possible with PHP as it is client side.

Again, I've tried many methods.. this is what I've got at the moment.
Code: [Select]
<script type="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
document.form.submit();
return false;
}
else
return true;
}
//-->
</script>

<form>
    <textarea name="nonaction" cols="50" rows="3" wrap="virtual" id="rptext" class="textarea" onKeyPress="return submitenter(this,event)"></textarea>
      <input type=submit value=SUBMIT>
</form>

Thoguh it doesn't work, though yes. It is a text area.
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: submit form on enter button
« Reply #7 on: March 12, 2010, 06:53:10 PM »
PHP doesnt actually have forms. Try htmlfreaks.com

Bad link :(
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: submit form on enter button
« Reply #8 on: March 12, 2010, 07:00:23 PM »
PHP doesnt actually have forms. Try htmlfreaks.com

Bad link :(

I think Tazerenix was just hinting that your question was in the wrong board.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: submit form on enter button
« Reply #9 on: March 12, 2010, 07:00:53 PM »
spot on
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: submit form on enter button
« Reply #10 on: March 12, 2010, 07:03:34 PM »
Considering the enter key only does new lines and doesn't submit the form. Quite impossible.

Oh and I just noticed, this is the wrong place for this post >.< Sorry

I realised, it's put in that post >.<
Should I repost?
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: submit form on enter button
« Reply #11 on: March 12, 2010, 07:04:33 PM »
Considering the enter key only does new lines and doesn't submit the form. Quite impossible.

Oh and I just noticed, this is the wrong place for this post >.< Sorry

I realised, it's put in that post >.<
Should I repost?

No, double posting is NOT allowed. Your thread has been moved (twice) and is now in the correct location.

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: submit form on enter button
« Reply #12 on: March 12, 2010, 07:05:49 PM »
Oh. Ok. I am sorry.
Can you help me with why it doesn't work with the code up there ^
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.