I was wanting to use a multi-form script, but I can not. So I'm generating a script for each form with unique IDs for each field and form.
I'm not able to inhibit the behavior of the form, every time I click the submit button and reloaded.
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Teste ajax jquery tutsmais</title>
<script src="jquery-1.12.4.min.js"></script>
<script>
$("#form1").submit(function(e){
return false;
$.ajax({
type : 'post',
url : 't2.php',
data : '&nome=' + $('#nome1').val() + '&sobrenome=' + $('#sobrenome1').val(),
dataType : 'html',
success : function(txt){
$('#div1').html(txt);
}
});
});
</script>
<script>
$("#form2").submit(function(e){
return false;
$.ajax({
type : 'post',
url : 't2.php',
data : '&nome=' + $('#nome2').val() + '&sobrenome=' + $('#sobrenome2').val(),
dataType : 'html',
success : function(txt){
$('#div2').html(txt);
}
});
});
</script>
<script>
$("#form3").submit(function(e){
return false;
$.ajax({
type : 'post',
url : 't2.php',
data : '&nome=' + $('#nome3').val() + '&sobrenome=' + $('#sobrenome3').val(),
dataType : 'html',
success : function(txt){
$('#div3').html(txt);
}
});
});
</script>
<script>
$("#form4").submit(function(e){
return false;
$.ajax({
type : 'post',
url : 't2.php',
data : '&nome=' + $('#nome4').val() + '&sobrenome=' + $('#sobrenome4').val(),
dataType : 'html',
success : function(txt){
$('#div4').html(txt);
}
});
});
</script>
<script>
$("#form5").submit(function(e){
return false;
$.ajax({
type : 'post',
url : 't2.php',
data : '&nome=' + $('#nome5').val() + '&sobrenome=' + $('#sobrenome5').val(),
dataType : 'html',
success : function(txt){
$('#div5').html(txt);
}
});
});
</script>
</head>
<body>
<div id="div1">
</div>
<h2>form via ajax</h2>
<form id="form1">
Digite seu nome: <input type="text" id="nome1"><br>
Digite seu sobrenome: <input type="text" id="sobrenome1"><br>
<input type="submit" id="id1"><br>
</form>
<div id="div2">
</div>
<h2>form via ajax</h2>
<form id="form2">
Digite seu nome: <input type="text" id="nome2"><br>
Digite seu sobrenome: <input type="text" id="sobrenome2"><br>
<input type="submit" id="id2"><br>
</form>
<div id="div3">
</div>
<h2>form via ajax</h2>
<form id="form3">
Digite seu nome: <input type="text" id="nome3"><br>
Digite seu sobrenome: <input type="text" id="sobrenome3"><br>
<input type="submit" id="id3"><br>
</form>
<div id="div4">
</div>
<h2>form via ajax</h2>
<form id="form4">
Digite seu nome: <input type="text" id="nome4"><br>
Digite seu sobrenome: <input type="text" id="sobrenome4"><br>
<input type="submit" id="id4"><br>
</form>
<div id="div5">
</div>
<h2>form via ajax</h2>
<form id="form5">
Digite seu nome: <input type="text" id="nome5"><br>
Digite seu sobrenome: <input type="text" id="sobrenome5"><br>
<input type="submit" id="id5"><br>
</form>
<p></p>
</body></html>
The other problem I was encountering before making this change was that by using the fields and the submit button outside of the form, clicking any submit button on the page was sending all the fields.