JQuery Code Snippet For Select Lists

Bell Boy

JQuery Code Snippet For Select Lists

This code will help display a special note when a specific value from a select list is chosen. In this example, some note text is added to the page, near the form save button.

This script can then be set in a Drupal "code" block, with conditions for only displaying on our node add/edit form page.

<script>
(function ($) {
$(document).ready(function(){
$('#select_list_div_id').change(function()
{
if (this.value == 'some_value_from_select_list')
{
$('<div id="special_note"><H1>Special Note:</H1> Note text here. </div>').insertBefore('#existing_div_id_of_where_to_place_on_page');
} else if ($('#special_note').length){
// Check for length (existence) of our note div.
// This removes our note if the value is selected and then changed to another value.
$("div").remove( "#special_note" );
}
});
});
}(jQuery))
</script>