0

I want 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?

3 Answers 3

2

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'); });
Sign up to request clarification or add additional context in comments.

Comments

1

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).

Comments

1

you can use this property of

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.