Search code examples
jquerydrupal-7drupal-webform

Running jquery on webform submit


I've created a jquery function to score a webform based on user input and display the scores in disabled number fields on the webform when the user clicks a Score button. I would also like the function to run again when the user clicks submit, in order to capture any changes made to responses after the user clicked the score button. I've tried a couple of different ways of referring to the submit button, none are working. Is there a way of running jquery between clicking Submit and actually submitting the form?

function caclulateScore() {
// does awesome stuff
};
$("#score").click(calculateScore);
//This works as intended.

$("#submit").click(calculateScore);
$("#submit").submit(calculateScore);
$("input[name=op]").click(calculateScore);
//These do not.

Solution

  • Try the following code. It will call calculateScore() before actually submitting the form.

    $("#submit").submit(function(){
        calculateScore();
    });