0

I'm a newbie to jQuery and I would like to display a text box below if the user selects "Other". How will I select the individual item in the radio box?

Also, when the user un-clicks the OTHER button then the textbox should be removed.

<html>

    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">

        </script>
        <script>
            $(document).ready(function() {
                $("$select-car").click(function() {

                });
            });
        </script>
    </head>

    <body>
        <div id="select-car">
            <input type="radio" name="car" value="Toyota">GM<br>
            <input type="radio" name="car" value="Honda">Ford<br>
            <input type="radio" name="car" value="Other" onlick>Other<br>
        </div>
    </body>

</html>
1
  • means you want to show/hide textbox on check/uncheck event of radio button ? Commented Nov 19, 2013 at 4:51

2 Answers 2

3
$("#select-car input[type='radio'][name='car']").change(function () {
    if (this.value === 'Other') {
        //show textbox $('#txt').show();
    }
    else{
        //hide textbox $('#txt').hide();
    }
});


References

.change()

multiple attribute selector

this keyword

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

Comments

0

ok than add textbox below your html like this :

<input style="display:none;" type="text" name="mytext" id="mytext"/>

write jQuery like this

$("input[type='radio']").change(function () {
    if ($(this).val() == "Other") {
        $("#mytext").show();
    } else {
        $("#mytext").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.