0

I am new to javascript any advice will be really much appreciated I am trying to hide my button and show it based in the value that been loaded to a field but my below code is not working

there is a field named ook if page loaded there will be a value display in ook it depends on the database but it will be loaded in page I want my button to hide if value is not yes

    $(document).ready( function(){

           var k = FormUtil.getField("ook").val();

           if ( k ='YES') {

               $("#btn).show();

           } else {  $("#btn).hide();
        }
    });
9
  • Why is your code all over the place like that? Please use the refactoring/beautifier utilities of your IDE. Commented Aug 29, 2018 at 17:46
  • 1
    I am only beginner I am trying to learn it thank you for the advice Commented Aug 29, 2018 at 17:48
  • 2
    There are a few syntax errors with this code that you should fix first. #1) Your $(function(){} is missing a closing ); #2) Your else { is missing a closing }. #3) Your $("#btn) is missing the " to make it correctly written as $("#btn") Commented Aug 29, 2018 at 18:00
  • Also, $(document).ready() and $(function(){}) are effectively the same thing, so you are doing the same thing twice. You only need one of those, so pick which one you like better and remove the other. Commented Aug 29, 2018 at 18:00
  • 1
    condition is wrong - use == instead of = to check equality Commented Aug 29, 2018 at 18:13

2 Answers 2

2

$(document).ready( function(){

    $(function(){



           var k = FormUtil.getField("ook").val();

       if ( k ='YES')
       {

           $("#btn).css("display" ,"block")




           } else {  $("#btn).css("display ,"none")

}

});



});

Sign up to request clarification or add additional context in comments.

6 Comments

It may be helpful to include a short explanation of your code.
Yes, explanation of above-mentioned code is You can hide or show of your div using method .css() of jQuery.
Have you checked the value of "k" when page is load , if value is not assigned then you can set false as a default value & then check ook filed return value
Oh, sorry. Please the else part with $("#btn").css("display ,"none")
@sonal.paghdal bottom left of your post there is an 'edit' button that you can use to edit and fix your post.
|
0

You had a typo in condition ( k ='YES'), also in $("#btn) selectors

$(document).ready( function(){

       var k = FormUtil.getField("ook").val();

       if ( k == 'YES') {

           $("#btn").show();

       } else {  
           $("#btn").hide();
       }
});

Comments

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.