0

I have a column name "Order" and if order is equal to "Car" then show the "Warranty" field, else hide it. I am using script editor for this and here is my code and someone it is not working. Can you point me to a right direction.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script>

if ($("select[title='Order']").val() != "Car")
{
$(document).ready(function(){
$("nobr:contains('Warranty')").closest('tr').hide();
});

}

else 
{
$(document).ready(function(){
$("nobr:contains('Warranty')").closest('tr').hide();
});

}
</script>
  • What is the data type of warranty and Order fields? – Ganesh Sanap Aug 6 at 14:50
  • Warranty is check box(Yes or No) but Order is multiple choice. – user85780 Aug 6 at 15:30
0

Assuming your jQuery selectors or right, you can try using below code:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    if ($("select[title='Order']").val() == "Car")
    {           
      $("nobr:contains('Warranty')").closest('tr').show();  
    } 
    else 
    {           
      $("nobr:contains('Warranty')").closest('tr').hide();  
    }
});
</script>
  • Somehow it doesn't work. It just hides it. if the condition were true then it never shows. – user85780 Aug 6 at 15:27
  • Try adding breakpoint from browser's console at IF condition and see if you are getting correct select element or not. – Ganesh Sanap Aug 6 at 16:03
0

If the "Order" field is a lookup field and allow multiple select, we can use the code below to achieve it.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    $("nobr:contains('Warranty')").closest('tr').hide();
    $("select[title='Order selected values'] option").each(function(){
        if($(this).text()=="Car"){
            $("nobr:contains('Warranty')").closest('tr').show();
        }
    });
});
</script>

enter image description here

If the "Order" field is a dropdown list, we can use the code below.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    $("nobr:contains('Warranty')").closest('tr').hide();
    if($("select[title='Order']").val()=="Car"){
        $("nobr:contains('Warranty')").closest('tr').show();
    }
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.