webb
webb

Reputation: 215

How to reset inputs based on radio button clicked

I have two radio buttons that show parts of a form when clicked as the page is blank when initialised. The parts of the form are located in two different divs. The code below takes care of that very well

$(document).ready(function() {
    $("input[name$='btnyes']").click(function() {
        var test = $(this).val();
        $("div.hidemyforms").hide();
        $("#" + test).show();
        $("div.showsubmit").show();

});

});

Radio buttons

     <input type="radio" name="btnyes" id="btnyes" value="getmytimeregular" />Yes
     <input type="radio" name="btnyes" id="btnyes" value="getmytimetaken" />No

I'm trying to target the div #getmytimetaken and reset the inputs with the following code when the div #getmytimeregular is visible if the user had selected any previously.

    $("#getmytimetaken").hide().find("input").val("");

Also if the div #getmytimeregular is visible i need this code not to run as it targets the div #getmytimetaken and ceates errors.

$('.ft4').change(function() {
    var goo = $('.ft4[selectedIndex!=0]').length;
    if (goo >= 1) $('.ft4[selectedIndex=0]').attr('disabled', 'disabled');
    else $('.ft4').removeAttr('disabled');

});

Upvotes: 0

Views: 228

Answers (1)

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

I don't undestand exactly what you are asking, but it seems to me you are trying to do something based on the visibility of a div. In this cas you could use:

if($("#getmytimetaken").is(':visible')){
///code to execute if the div is visible
$("#getmytimetaken input:radio").removeAttr('checked')
}else{
///code to execute if the div is not visible
}

Upvotes: 1

Related Questions