I am editing a website in Drupal 7, and using a custom JS file to add a bit of scripting functionality to a form that I created with the Webform module.
Basically, there is a checkbox that, if checked, will prevent the user from having to fill in redundant fields on the form if the information from one section also applies to the other section.
This is my code, for now I am just testing to see if the information gets passed between the functions.
$(document).ready(function() {
var checkbox = $("#edit-submitted-contact-information-pi-checkbox-1");
checkbox.onchange = "checkPI(this);";
});
function checkPI(x) {
if(x.checked) alert("Checkbox is checked");
else alert("Checkbox is unchecked.");
}
When I click the checkbox, however, nothing happens. I double checked and the JS script is being added to the page by Drupal (in the .info file I added scripts[] = myjs.js and also linked jQuery before that.
Upon doing other alert() tests, I found that it is finding the check() function from the document ready handler.
Am I missing something/not doing something a certain way?
Also note: I have to make sure this site works in IE 8, so I cannot use the setAttribute() method to add the onchange listener.
setAttributein IE8. here's how: stackoverflow.com/questions/15329292/…setAttributeto get this working at all?