I've got a Webform for which I need additional calculations to hidden fields.
I've added a JavaScript file to the page by using drupal_add_js
. And let that be the only part that works...
My calculate.js file looks like this:
document.getElementById("webform-client-form-80").onsubmit = function() {
window.alert("Test!");
document.getElementsByName("submitted[aantal18plus]")[0].value = 5;
};
Why don't I get an alert? And why doesn't the value of "submitted[aantal18plus]" get altered?
If I change "document.getElementById("webform-client-form-80").onsubmit" to "document.onload", everything works. But unfortunately, there isn't any data yet (tried with windows.alert("");)
A bit more context:
The form is a subcription form for a BBQ. I Have 16 fieldsets (for 16 persons at once) with 4 dropdown menus (for choice of meat). A LOT of fields, and a lot of different prices. I want to calculate things like 'total' and 'number of steaks'. I want to send those in the submission e-mail, so I created 12 hidden fields, and I do need to calculate those values on submit.
I don't (necessary) need JQuery. At submit will do fine, 'cause the fields I'm altering are hidden.
Simply put: onsubmit
, how on earth do I get it to work with javascript in drupal??