javascript - Having trouble submitting form on return key -


i need asap, have form on page it's 1 inout field email , button submits email , writes txt file.

it connected js script writes txt file:

if ($('#subscribe').is(":visible")) {      $("#subscribe button").click(function() {          var email   = $("#email").val();         var emailreg =  /^[a-za-z0-9._+-]+@[a-za-z0-9-]+\.[a-za-z]{2,4}(\.[a-za-z]{2,3})?(\.[a-za-z\s\s*]{2,3})?[-a-za-z0-9_:,.\s]$/ ;          // client-side validation            if(emailreg.test(email) == false)             return false;          $.ajax({             type: "post",             datatype: "json",             url: "save-email.php",             data: $("#subscribe").serialize(),             success: function(data) {                  $('#subscribe').html('<p > <img style="position:relative; bottom:45px;left:30px;"src="assets/img/confirm.png" /></p>');              }         });          return false;     });   }; 

i need filed submit email txt file when user clicks return. can't seem work. please help. thanks

try this

if ($('#subscribe').is(":visible")) {     function submit() {          var email   = $("#email").val();         var emailreg =  /^[a-za-z0-9._+-]+@[a-za-z0-9-]+\.[a-za-z]{2,4}(\.[a-za-z]{2,3})?(\.[a-za-z\s\s*]{2,3})?[-a-za-z0-9_:,.\s]$/ ;          // client-side validation            if(emailreg.test(email) == false)             return false;          $.ajax({             type: "post",             datatype: "json",             url: "save-email.php",             data: $("#subscribe").serialize(),             success: function(data) {                  $('#subscribe').html('<p > <img style="position:relative; bottom:45px;left:30px;"src="assets/img/confirm.png" /></p>');              }         });          return false;     }     $("#subscribe button").click(submit);     $("form").submit(submit);  }; 

note: can remove $("#subscribe button").click(submit); if convert button input type submit


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -