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 4025006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:47:34+00:00 2026-05-20T10:47:34+00:00

I’ve got a form with some radio buttons in it. When a link is

  • 0

I’ve got a form with some radio buttons in it. When a link is clicked, the value of the selected radio button is passed to a text field. If the value is ‘0’, the text ‘Not required’ is given to a div, overwriting where the output would have been if it wasn’t ‘0’.

When you click the ‘0’ radio button then click the link, it works as it should. The problem is that if you change to a different radio button then click the link again, the text remains. What I want to happen is for that message to only appear when the ‘0’ is selected and for it to be removed if a non-‘0’ is chosen.

I’ve set it up on http://jsfiddle.net/thewebdes/gnW2c/ so you can see what I mean. In the actual project, the ‘Not required’ text will overwrite anything else that would have appeared so clearing the html using jquery at the beginning of the click function is a no-go.

HTML

<form action="#" method="post">
    <label for="item1_qty1">0</label>
    <input type="radio" id="item1_qty1" name="item1_qty" value="0">
    <br>
    <label for="item1_qty1">100</label>
    <input type="radio" id="item1_qty1" name="item1_qty" value="100">
    <br>
    <label for="item1_qty1">250</label>
    <input type="radio" id="item1_qty1" name="item1_qty" value="250">
    <br>
    <label for="item1_qty1">500</label>
    <input type="radio" id="item1_qty1" name="item1_qty" value="500">

    <a href="javascript:;" class="gen_output">Get Value</a>

    <div class="output">
        <label for="item1_qty_output">Item 1 Output</label>
        <input type="text" id="item1_qty_output">
    </div>
</form>

JS

$('.gen_output').click(function() {
    $('#item1_qty_output').val($('input:radio:checked').val());
    if ($('input:radio:checked').val() == '0') {
        $('.output').html('Not required')
    }
});
  • 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-20T10:47:35+00:00Added an answer on May 20, 2026 at 10:47 am

    You were replacing all the content with .html, so your inputs werent there when you tried to update them.

    http://jsfiddle.net/loktar/gnW2c/6/

    JS

    $('.gen_output').click(function() {
        $('#item1_qty_output').val($('input:radio:checked').val());
        if ($('input:radio:checked').val() == '0') {
            $('#msg').html('Not required').show();
            $('#fields').hide();
        }else{
             $('#fields').show();   
            $('#msg').hide();
        }
    });
    

    Markup

    <form action="#" method="post">
        <label for="item1_qty1">0</label>
        <input type="radio" id="item1_qty1" name="item1_qty" value="0">
        <br>
        <label for="item1_qty1">100</label>
        <input type="radio" id="item1_qty1" name="item1_qty" value="100">
        <br>
        <label for="item1_qty1">250</label>
        <input type="radio" id="item1_qty1" name="item1_qty" value="250">
        <br>
        <label for="item1_qty1">500</label>
        <input type="radio" id="item1_qty1" name="item1_qty" value="500">
    
        <a href="javascript:;" class="gen_output">Get Value</a>
    
        <div class="output">
            <div id="msg"></div>
            <div id="fields">        
                <label for="item1_qty_output">Item 1 Output</label>
                <input type="text" id="item1_qty_output">
                </div>
        </div>
    </form>
    

    Just added each one in the output container div, then do a hide/show.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.