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

  • SEARCH
  • Home
  • 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 5937331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:31:27+00:00 2026-05-22T15:31:27+00:00

I want to show/hide elements on the page depending on whether 2 form inputs

  • 0

I want to show/hide elements on the page depending on whether 2 form inputs match. So in this example, if a text field is greater than 100000 and a radio button has a certain value, said elements will show. If correct radio is still selected, but the numerical value drops below 100000, then elements hide. (This code is part of a much larger script, in case it doesn’t make sense).

It works for the most part, but the text field’s onchange/onkeyup event doesn’t fire on its own when used with a radio value onclick event. I have to reclick the radio button for a changed text field value to fire the event. (And it is not an onblur issue. onchange works fine on its own, but not with a logical && operator.)

    <li id="f-container-applicant-bondamount">
        <label for="f-applicant-bondamount">Amount of Bond</label>
        <input type="text" name="ApplicantBondAmount" id="f-applicant-bondamount" onkeypress="showMoreInfo(this);" />
    </li>

    <li id="f-container-applicant-is"> 
        <label for="f-applicant-is">Applicant is...</label> 
            <ul>
                <li>
                    <label for="f-applicant-is_0">
                    <input type="radio" name="ApplicantIs" id="f-applicant-is_0" value="Administrator" onclick="showMoreInfo(this);" />
                    Administrator
                    </label>
                </li>
                <li>
                    <label for="f-applicant-is_1">
                    <input type="radio" name="ApplicantIs" id="f-applicant-is_1" value="Executor" onclick="showMoreInfo(this);" />
                    Executor
                    </label>
                </li>
            </ul>
        </label>
    </li>

    <li id="f-container-applicant-moreinfo">
        <label for="f-applicant-moreinfo">More Info</label>
        <input type="text" name="ApplicantMoreInfo" id="f-applicant-moreinfo" />
    </li>




function showMoreInfo(x) {
    var bond = document.getElementById('f-applicant-bondamount');
    var y = bond.value;

    if (y > 100000 && x.value == "Administrator")  {
        document.getElementById('f-container-applicant-moreinfo').style.display = 'block';      
    }
    else if (y <= 100000 && x.value == "Administrator") {
        document.getElementById('f-container-applicant-moreinfo').style.display = 'none';
    }
}

Thanks in advance.

  • 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-05-22T15:31:27+00:00Added an answer on May 22, 2026 at 3:31 pm

    EDIT:
    Your code doesn’t work because the showMoreInfo(x) function assumes that the x parameter will be a reference to one or the other of the radio buttons, but then your text input’s onchange/onkeyup/whatever event is calling the same function and passing in a reference to itself – this is why it only works when you click the radio buttons. You could try something like the following instead, letting the function work out its own references to your HTML elements instead of passing them in:

    function showMoreInfo() {
       var bond = document.getElementById('f-applicant-bondamount');
       var adminRadio = document.getElementById('f-applicant-is_0');
       // var theOtherRadioIfYouNeedIt = document.getElementById('f-applicant-is_1');
    
       var y = bond.value;
    
       if (y > 100000 && adminRadio.checked) {
          document.getElementById('f-container-applicant-moreinfo').style.display = 'block';
       }
       else if (y <= 100000 && adminRadio.checked) {
          document.getElementById('f-container-applicant-moreinfo').style.display = 'none';
       }
    }
    

    My original point about keyboard events being inadequate still stands though.

    My original answer:

    As wombleton said, onchange only happens when focus leaves the field – which is why in your example clicking on the radio button makes the onchange happen. So as has been said already you can use onkeyup instead of onchange.

    But, remember that there are several ways that the user can change the value in an input without using the keyboard (thus no onkeyup), e.g., drag-and-drop onto the input (drag out will change the focus, but if you’re not using onchange any more…). Or right-click-context-menu-paste, cut or delete. Off-hand I’m not sure what the simplest way to cater for these is (I haven’t needed to worry since I don’t like having things on the page change as the user types within a field and I generally only need onkeyup to check specifically for the enter key), but there are onpaste and ondrop events you could look into.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://jsfiddle.net/MEKRM/ This is my fiddle I want to show / hide elements when i
I have about 25 show/hide (toggle) elements on a page like so... HTML: <h2><a
I have the following code to hide/show elements depending on what value is selected
I have a viewstack with childrens which I want to show/hide depending on the
I have some nested tables that I want to hide/show upon a click on
I want to dynamically hide/show some of the columns in a NSTableView, based on
Bascially I want to know the best way to hide/show an ASP.NET control from
I use Jquery in my page to hide buttons which i dont want to
I have a form element, that is hidden or show depending on a dropdown
I have a select field that shows different elements of my form based on

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.