how would I execute a JavaScript function on a PHP form before submit but after all text is entered?
let's say I want to make all the text uppercase or something.. would onsubmit execute before the PHP takes over?
asked Jul 30, 2012 at 21:43
cream
1,1275 gold badges16 silver badges26 bronze badges
2 Answers 2
Yes, onSubmit event will be before PHP. Here is jsFiddle example with jQuery. Of course you can use native event handler or whatever you like. I use that, bacause it is faster :)
answered Jul 30, 2012 at 21:57
Setthase
14.5k2 gold badges29 silver badges30 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Here is a non-jQuery jsfiddle version, that uses the onSubmit handler.
answered Jul 30, 2012 at 22:31
justinwehrman
3402 silver badges4 bronze badges
Comments
lang-js
onsubmithandler and when the handler completes, the web browser sends the HTTP request to your web server, which forwards it to PHP. Fun fact: if you returnfalsefrom your onsubmit handler, the web browser aborts the form submit and never sends the HTTP request.