www.webdeveloper.com
Results 1 to 4 of 4

Thread: Hide a button with JQuery based on a variable

  1. #1
    Join Date
    Dec 2013
    Posts
    6

    Hide a button with JQuery based on a variable

    Hi all,

    I can parse some variables within my environment. Eg {approver#value} will give a true when the person who is logged in, is an approver.
    I have the following code within my web application:

    Code:
    <form style="margin: 0px auto 0px auto; text-align: center;">
    <div class="btn-group" style="margin: 0px auto 0px auto; text-align: center;">
    <button type="button" class="btn btn-default navbar-btn">Approve</button>
    <button type="button" class="btn btn-default navbar-btn">Reject</button>
    </div>
    </form>
    If i change this into:


    Code:
    <form style="margin: 0px auto 0px auto; text-align: center;">
    <div class="btn-group" style="margin: 0px auto 0px auto; text-align: center;">
    <button type="button" class="btn btn-default navbar-btn">{approver#value}</button>
    <button type="button" class="btn btn-default navbar-btn">Reject</button>
    </div>
    </form>
    the caption of the approve button contains the text: true. Now i want to hide this approve button when it is true. How can i do this with jquery?

    I have tried a lot of stuff, but could not realize it.


    Any idea's?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,635
    {approver#value} looks kind of weird for jQuery synthax... anyway, if the caption of the approve button contains the text 'true', you can try this:

    Code:
    <script>
    $('button:contains("true")').hide();
    </script>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Dec 2013
    Posts
    6
    Quote Originally Posted by Padonak View Post
    {approver#value} looks kind of weird for jQuery synthax... anyway, if the caption of the approve button contains the text 'true', you can try this:

    Code:
    <script>
    $('button:contains("true")').hide();
    </script>
    Hi Padonak,
    That was just an example (the variable as a caption which returns true). So i can declarare it everywhere, it return true or false. Its a variable, which i can use within my webapplication.

    How can i use this information (the variable {approver#value} which returns true). If this is true i want to show the button, and when its false i want to hide. Any idea?

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,635
    in your previous post it was 'i want to hide this approve button when it is true' and now you say 'If this is true i want to show the button, and when its false i want to hide'. i think you should first decide what you really want. in any case, the code i posted above

    Code:
    <script>
    $('button:contains("true")').hide();
    </script>
    will work with your second html

    Code:
    <form style="margin: 0px auto 0px auto; text-align: center;">
    <div class="btn-group" style="margin: 0px auto 0px auto; text-align: center;">
    <button type="button" class="btn btn-default navbar-btn">{approver#value}</button>
    <button type="button" class="btn btn-default navbar-btn">Reject</button>
    </div>
    </form>
    according to your first condition (i want to hide this approve button when it is true) if {approver#value} prints 'true' in the markup and you can change it to fit your needs
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles