Hi,
I've been trying to add some jquery to a webform to make dependent drop-downs and also disable certain fields if others haven't been filled out etc.
But it's not working! I don't know javascript so I'm trying to borrow code from some of the other threads. I've added a webform-form.tpl.php to my theme folder, And inside I've placed:
drupal_add_js(path_to_theme() . '/scripts/odgerswebform.js');
(where odgerswebform.js) is the script I want to run.
And the script itself is:
$(document).ready(function() {
$("#edit-submitted-d-ethnic-origin").change(function () {
if ($("#edit-submitted-d-ethnic-origin").val() == 'White'){
$("#webform-component-d-white-options").css("display","block");
} else {
$("#webform-component-d-white-options").css("display","none");
}
if ($("#edit-submitted-d-ethnic-origin").val() == 'Black'){
$("#webform-component-d-black-options").css("display","block");
} else {
$("#webform-component-d-black-options").css("display","none");
}
if ($("#edit-submitted-d-ethnic-origin").val() == 'Asian'){
$("#webform-component-d-asian-options").css("display","block");
} else {
$("#webform-component-d-asian-options").css("display","none");
}
if ($("#edit-submitted-d-ethnic-origin").val() == 'Mixed'){
$("#webform-component-d-mixed-options").css("display","block");
} else {
$("#webform-component-d-mixed").css("display","none");
}
});
});
Not sure what is wrong but any advice really appreciated! If it helps to have a link to the form directly it's here:
http://www.abbevilleassociates.co.uk/content/diversity-monitoring-part-i
Thanks, I really need an answer urgently to this.
Nicl
Comments
Thanks for the link, that
Thanks for the link, that really helps. I think you just have to look closely at your jQuery selectors. Some of them do not match any element in the page, so nothing gets hidden. For instance, I believe that "#webform-component-d-white-options" should be "#webform-component-white_options" in your code.
The link is dead
Trying to manage to put webforms into jquery popins... Anybody have done it?
Not sure if this is what you
Not sure if this is what you mean but on this site I just did (I'm more an amateur than pro so I know it isn't perfect!) I contain a webform in an element which appears using jquery.
http://www.madhattersmayball.com/night
Just try clicking on the 'ticket' button on the far left of the screen...