开发者

Run JavaScript code on form submission

开发者 https://www.devze.com 2023-03-09 11:46 出处:网络
I wa开发者_StackOverflow社区nt to run a JavaScript code upon a form being submitted preceding other default tasks that are carried out on form submit.

I wa开发者_StackOverflow社区nt to run a JavaScript code upon a form being submitted preceding other default tasks that are carried out on form submit.

Can anyone suggest some approaches?


For example, here is how you can execute some JS on Drupal's contact form before it is submitted using jQuery:

$('form#contact-mail-page input#edit-submit').click(function() { alert('do some stuff'); });


I am not sure if drupal has any special way to automate this or make it easier but in just normal HTML javascript you would do it like:

<input type="submit" onClick="doStuff();" value="Submit">  //Note: you can use return(doStuff()); and if doStuff returns false then the form will not submit (great for checking if all fields are filled out correctly).


you can use this property of

'#attributes' => array('onclick' => 'if(confirm('.$msg.')) return true; return false;'));
0

精彩评论

暂无评论...
验证码 换一张
取 消