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>
2
  • What is the data type of warranty and Order fields? Commented Aug 6, 2019 at 14:50
  • Warranty is check box(Yes or No) but Order is multiple choice. Commented Aug 6, 2019 at 15:30

2 Answers 2

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>
2
  • Somehow it doesn't work. It just hides it. if the condition were true then it never shows. Commented Aug 6, 2019 at 15:27
  • Try adding breakpoint from browser's console at IF condition and see if you are getting correct select element or not. Commented Aug 6, 2019 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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.