ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How to submit a form by clicking enter and not via an existing submit button?

user-image
تم إضافة السؤال من قبل Besim Dauti , Ceo / Front End Developer , Nunforest
تاريخ النشر: 2013/04/14
مستخدم محذوف‎
من قبل مستخدم محذوف‎

Basically, having a button of type "submit" in the form will handle the "enter" event without the need of any script.

wael kassis
من قبل wael kassis , Tech Lead , NETNOVUS

I think you should go the Javascript route, or at least I would // Using jQuery.
$(function() { $('form').each(function() { $('input').keypress(function(e) { // Enter pressed? if(e.which == 10 || e.which == 13) { this.form.submit(); } }); $('input[type=submit]').hide(); }); });

Feras Abualrub
من قبل Feras Abualrub , Web Solutions Manager , Qistas for Information Technology

use jquery to submit a form by serializing all inputs you want to submit.
the below code is an ajax , for you take the first line which takes all input values located in a function SubmitData() { var Data = $(".cs_slider").find('select').serialize() + '&'+ $(".cs_slider").find('input').serialize() + '&' + $(".cs_slider").find('textarea').serialize(); $.ajax({ url:'SubmitData.php', data: Data, type: 'POST', success: function(rData) { alert(rData); } }); }

Ankur Dadhich
من قبل Ankur Dadhich , Senior subject matter expert , Amdocs

Dude, JQuery is the next thing that is used , the good old Javascript is gone out.
for your question use this....
code..............
You need to refer the latest jquery library over this block to work.
$(function() { Submitform(); }); functtion Submitform() { //Change #form to your form's ID $('#form input').keydown(function(e) { if (e.keyCode == 13) { $('#form').submit(); } }); }

Furqan Ul Karim
من قبل Furqan Ul Karim , Senior Delivery Manager (Contract) , Virgin Red

I have recently created a form on the run-time and got it submitted without a need to click on a submit button.
Well this is not a magic just a normal javascript function i used for it.
there are 2 ways you can do it either you code the form to submit on body load event e.g.
see this below Hope it will help

Ashraf Sabry
من قبل Ashraf Sabry , Freelancer developer , N/A

As Abdelhamid ABID pointed, a form with a button (submit or normal button) will submit on pressing Enter automatically without any JavaScript intervention.
If you want to remove the button and make Enter the only submission method, just catch the event on the FORM element (the onkeypress event bubbles from children to the form itself): $("form").on("keypress", function(e) { if(e.which == 13) this.submit(); }); Try it on JSFiddle http://jsfiddle.net/ashraf_sabry_m/hYeTf/1/

المزيد من الأسئلة المماثلة