Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:05+00:00 2026-06-15T12:19:05+00:00

I want to hide and show a button on a particular condition in JavaScript.

  • 0

I want to hide and show a button on a particular condition in JavaScript.

Code:

$(function(){
    // hide the div initially
    $("#a").hide();

    // Check to see if there is 250 in the url
    var bal_amount = document.getElementById('balance_amount');
    if (bal_amount.value > 0) {
        $("#a").show();
    }
});

HTML

<form>
<input type="text" id="balance_amount">
</form>

<image src="image.jpg" id="a">

But it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:19:06+00:00Added an answer on June 15, 2026 at 12:19 pm

    You will need to change this portion of your code –

    // Check to see if there is 250 in the url
    var bal_amount = document.getElementById('balance_amount');
    if (bal_amount.value > 0)
    {
        $("#a").show();
    }
    

    You are executing the above piece of code inside document ready event, which means it will be executed right when the page loads, and only once.

    To remedy this, you need to place this code inside an event handler –

    ​$(document).ready(function () {
        $("#a").hide();
    
        // See this? This is the event handler for the
        // change event which will fire whenever the value
        // of the text box changes.
        $('#balance_amount').change(function () {
            // Check to see if there is 250 in the url
            if ($(this).val() > 0) {
                $("#a").show();
            }
        });
    });​
    

    In this way, whenever the value of the balance_amount field changes, this event will trigger and validate your balance amount for your.

    Here you will find a working demo.

    You can further improve your code by checking for invalid input in the text box –

    ​$(document).ready(function () {
        $("#a").hide();
    
        // See this? This is the event handler for the
        // change event which will fire whenever the value
        // of the text box changes.
        $('#balance_amount').change(function () {
    
            var balance = parseInt($(this).val(), 10);
            if (isNaN(balance)) {
                alert('You have entered an invalid value');
                return false;
            }
    
            if (balance > 0){
                $("#a").show();
            }
    
            // There you go, an else block for you
            else {
                $("#a").hide();
            }
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a show/hide function for a <div> , using JavaScript/DOM properties.
I want some hide/show functionality with my div tag. I am using below code
I want to hide the tab,Only When i click on a particular button.There should
I want to achieve hide/show with div's in html but in this way. Here
all I want to show hide some ids using jQuery. My html code is
The code like this: $(.hide).click(function(){ $(.online-contact).animate({width: 'toggle',height: '100%'}, fast); $(this).hide(); $(.show-class).show(); }) I want
I want to dynamically hide/show controls in an activity based on a button touch
In my application I want to show/hide a button according to the users authorization
I want to show/hide jqgrid delete button on the basis of specific data in
Okay, so I'm trying to write a simple show/hide content button, but I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.