1

I am using the jquery function and it is not checking two conditions at once. I want to check for or condition.When I give only one condition in if statement it is working but after giving or it is not working. here is my code

if($("input[title='Nature of the work']").val() != "Execute Business processes" || $("input[title='Nature of the work']").val() != "Deliver periodic reports")
{
$('nobr:contains("Is the work being currently done")').closest('tr').hide();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').hide();
}
else
{
$('nobr:contains("Is the work being currently done")').closest('tr').show();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').show();
}

closed as off-topic by Christoffer, Robert Lindgren, Arsalan Adam Khatri, Mohamed El-Qassas MVP Apr 5 '18 at 0:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Christoffer, Robert Lindgren, Arsalan Adam Khatri, Mohamed El-Qassas MVP
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is the field Nature of the work required field? – Abdul Hameed Apr 4 '18 at 12:17
  • no it is not a required field in here – jayant khushalani Apr 4 '18 at 12:23
1

please try the below code , i added the full script , try and let me know

<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript&quot;"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            hideShow();
            $("input[title='Nature of the work']").change(function () {
                hideShow();
            });
        });

        function hideShow() {
            var txt = $("input[title='Nature of the work']").val();
            if ((txt != "Execute Business processes") && (txt != "Deliver periodic reports")) {
                $('nobr:contains("IIs the work being currently done")').closest('tr').hide();
                $('nobr:contains("Frequency of the Deliverables")').closest('tr').hide();
            }
            else {
                $('nobr:contains("Is the work being currently done")').closest('tr').show();
                $('nobr:contains("Frequency of the Deliverables")').closest('tr').show();
            }
        }
    </script>
  • i will let you know soon – jayant khushalani Apr 4 '18 at 13:39
  • this worked. but i did not write the whole function just used the variable initialization to input field. Thanks ! – jayant khushalani Apr 5 '18 at 4:54
0

Made some changes to your code, hope it should work.

if(!($("input[title='Nature of the work']").val() == "Execute Business processes" && $("input[title='Nature of the work']").val() == "Deliver periodic reports"))
{
$('nobr:contains("Is the work being currently done")').closest('tr').hide();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').hide();
}
else
{
$('nobr:contains("Is the work being currently done")').closest('tr').show();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').show();
}

Explanation: In your code, if any one of the condition is TRUE the IF statement will be executed as you have used OR operator, but in my code both the conditions will be checked as i have used AND operator.

if(A!=B || C!=D){
//do something
}

For checking both conditions,

if(!(A==B && C==D)){
//do something
}
  • but it is still not working for me ! – jayant khushalani Apr 4 '18 at 12:25
  • Is this the one you are expecting if(A!=B && C!=D) or explain what you need in simple terms. – Nagarajan Muthukumar Apr 4 '18 at 12:29
  • i have a input text field in the edit form. So if the input field is equal to Business unit or input field is equal to services i wanna show a dropdown but when i use or condition it does not work ! How do this in the code that i have given above? this is what i want : if(A!= B and A!=C){//do something} – jayant khushalani Apr 4 '18 at 13:18
  • it is working but it is showing only one of the items not both ! – jayant khushalani Apr 5 '18 at 4:25

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