When adding a document I want to show or hide colums based on a dropdown selection. In this case, the value of "Document type" is leading.
If a Travel Document (Column name "Travel Documents") is selected another column ("Employee") should become visible.
Therefore I've created following code with help from StackExchange:
<script src="/Shared%20Documents/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
// Execute the following JavaScript after the page has fully loaded, when it's ".ready"
$(document).ready(function(){
//Define which columns to show/hide by default
$('nobr:contains("Employee")').closest('tr').hide();
//Show/hide columns based on Drop Down Selection
$("select[title='Document type']").change(function() {
if ($("select[title='Document type']").val() == "Travel Documents") {
$('nobr:contains("Employee")').closest('tr').show();
else if($("select[title='Document type']").val() != "Travel Documents"){
$('nobr:contains("Employee")').closest('tr').hide();
}
});
});
</script>
For some reason it does not work at all and the Employee dropdown is Always shown. When I delete the next part:
else if($("select[title='Document type']").val() != "Travel Documents"){
$('nobr:contains("Employee")').closest('tr').hide();
the Employee dropdown is hidden, but I can't get it back with selecting the right Document type.
What am I doing wrong?
Travel Documentis selected in theDocument Typecolumn, theEmployeecolumn should appear. Else, it should be hidden?