I have the following scenario: Multiple forms, however, I need to set all inputs only from the form that is in action, which is triggered by the button.
function enviaForm(id){
$(id).submit(function(){
var answer = $("input[name='cbn']:checked").val();
var question = $(".thide").val();
var button = $(this).find('input[type="submit"]');
button.prop("disabled", true).val("respondido");
$.ajax({
type: "GET",
url: "proc_update_teste.php",
data: {
'campo1': answer,
'campo2': question,
},
success: function(result){
answer = $("input[name='cbn']:checked").parent().css('background', 'gray');
answer = $("input[name='cbn']").prop('disabled',true);
var question = $(".thide").val('');
var view = $('#resultSend').html(result);
}
});
return false;
});
}
<form id="q1">
<input class="thide" type="hidden" name="question1" value="q1">
<input class="with-gap" name="cbn" type="radio" id="q1a" value="answer1a"/>
<input class="with-gap" name="cbn" type="radio" id="q1b" value="answer1b" />
<input class="with-gap" name="cbn" type="radio" id="q1c" value="answer1c"/>
<input type="submit" value="RESPONDER" class="btn" onclick="enviaForm(q1)"></input>
</form>
<form id="q2">
<input class="thide" type="hidden" name="question2" value="q2">
<input class="with-gap" name="cbn" type="radio" id="q2a" value="answer2a"/>
<input class="with-gap" name="cbn" type="radio" id="q2b" value="answer2b"/>
<input class="with-gap" name="cbn" type="radio" id="q2c" value="answer2c"/>
<input type="submit" value="RESPONDER" class="btn" onclick="enviaForm(q2)"></input>
</form>
I'm using this code snippet answer = $("input[name='cbn']").prop('disabled',true);
to get to that end, except that it flips all forms when I need them to do just the form in action.