javascript - How to refresh the form value using JQuery -


I have an html form. I want to take the input value (a URL), use the regex ('/ [0-9] {5,} /') from the user, and then click on the form Refresh the number to remove the number and added to the other URL. If I do not get a number - I just have to see an error in the form box. Using Jquery to avoid all page reloads.

This is the current form

  & lt; Form id = "submit" method = "post" & gt; & Lt; Label = "link_website_url" & gt; Create a short URL & lt; / Label & gt; & Lt; Input id = "link_website_url" name = "link" size = "30" type = "text" /> & Lt; Input class = "go" name = "commit" type = "submit" value = "go!" / & Gt; & Lt; / Form & gt; Submit    

  $ ('# submit') (function () { Var url = $ ('# link_website_url'). Val (); //http://example.com/12345 var num = yourNumExtractor function (url); // Return if 1 will remove a number if (num & gt; - 1) {$ ('#link_website_url') .val ('http://otherdomain.com/' + num); //http://otherdomain.com/12345} and {$ ('# link_website_url'). ( '& Lt; span id = "error_link_web_url" class = "error" & gt; wrong format! Please try again. & Lt; / span & gt;'); return false; // error, submit it therefore}} );  

& nbsp;

If you perform additional verification, cancel the submit even after having a personal check, clear the check per error message (such as $ ('$ error_link_web_url)') .remove ();) and Submit after all check passes:

  var checkFailed = false; $ ('# Submit') Submit (function () {var url = $ ('# link_website_url'). Val (); //http://example.com/12345 var num = yourNumExtractor function (url); // if -1 ($ ' '(' #link_website_url ')) .val (' http://otherdomain.com/ '+ num); // http: // Other domains if a number is extracted, then gives -1. com / 12345 $ ( '# Error_link_web_url') Remove ();} Other {$ ('# link_website_url'). ('& Lt; span id = "error_link_web_url" class = "error" & gt; Incorrect format! Please try again. & Lt ; / Span & gt; '); Checkfell = true;} / * Other check ... * / if (checkfile) {return false; // cancel}});  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -