I'm having trouble sending forms correctly, I have several forms, each with its id, and a function that I call on all forms:
<script>
function enviaForm(id){
$(id).submit(function(){
var camp1 = $("input[name='a2']:checked").val();
$.ajax({
type: "GET",
url: "proc_update_teste.php",
data: {
'campo1': camp1
},
success: function(result){
camp1 = $("input[name='a2']:checked").val('');
var view = $('#resultSend').html(result);
}
});
return false;
});
}
</script>
<form id="q1">
<h1 class="flow-text white-text">Question 1</h1>
<input type="hidden" name="question1">
<p class="white-text">What is your father's last name?</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q1a" value="answer1a"/>
<label for="q1a">a. His last name Silva</label>
</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q1b" value="answer1b" />
<label for="q1b">b. My father last name is Silva</label>
</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q1c" value="answer1c"/>
<label for="q1c">c. His last name is Silva</label>
</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q1d" value="answer1d" />
<label for="q1d">d. My father is last name Silva</label>
</p>
<button class="btn" onclick="enviaForm(q1)">RESPONDER</button>
</form>
<hr>
<form id="q2">
<h1 class="flow-text white-text">Question 2</h1>
<input type="hidden" name="question2">
<p class="white-text">2. What do you do for a living?</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q2a" value="answer2a"/>
<label for="q2a">a. I am a doctor.</label>
</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q2b" value="answer2b"/>
<label for="q2b">b. I watch tv</label>
</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q2c" value="answer2c"/>
<label for="q2c">c. I´m teacher.</label>
</p>
<p>
<input class="with-gap" name="a2" type="radio" id="q2d" value="answer2d"/>
<label for="q2d">d. I live in São Paulo.</label>
</p>
<button class="btn" onclick="enviaForm(q2)">RESPONDER</button>
</form>
<hr>