Hello,
I have 2 form tags in my script which the user will submit separately without refreshing the page.
the example below has both forms. if i take out one of the form and the java script pertains to the form the script working and if in included both form and the js the script wontw ork.
Any ideas as to how to fix the problem?
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" >
$(function()
{ $(".submit1").click(function(e)
{
var fname = $("#fname").val();
var lname = $("#lname").val();
var dataString = 'fname='+ fname + '&lname=' + lname;
if(fname=='' || lname=='')
{ $('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{ $.ajax(
{ type: "POST",
url: "data1.php",
data: dataString,
success: function()
{ $('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
$("#fname").val("");
$("#lname").val("");
}
});
}
return false;
});
});
/**************************************************************************/
$(function()
{ $(".submit2").click(function(e)
{ var fname2 = $("#fname2").val();
var lname2 = $("#lname2").val();
var dataString = 'fname='+ fname2 + '&lname=' + lname2;
if(fname2=='' || lname2=='')
{ $('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{ $.ajax(
{ type: "POST",
url: "data1.php",
data: dataString,
success: function()
{ $('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
$("#fname2").val("");
$("#lname2").val("");
}
});
}
return false;
});
});
</script>
</head>
<body>
<div style="width:500px; height:100px; border:1px solid red;">
<div style="float:left; width:240px; border:1px solid green">
<?php echo rand(10,1000); ?>
</div>
<div style="float:left; width:240px; border:1px solid blue">
<form method="post" name="form1">
First name: <input name="fname" id="fname" type="text" /><br />
Last name: <input name="lname" id="lname" type="text" /><br />
<input type="submit" value="Submit" class="submit1"/>
<span class="error" style="display:none"> Please Enter Valid amount</span>
<span class="success" style="display:none"> Bid submitted</span>
</form>
</div>
</div>
<br><br>
<!--********************************************************************-->
<div style="width:500px; height:100px; border:1px solid red;">
<div style="float:left; width:240px; border:1px solid green">
<?php echo rand(10,1000); ?>
</div>
<div style="float:left; width:240px; border:1px solid blue">
<form method="post" name="form2">
First name: <input name="fname2" id="fname2" type="text" /><br />
Last name: <input name="lname2" id="lname2" type="text" /><br />
<input type="submit" value="Submit" class="submit2"/>
<span class="error" style="display:none"> Please Enter Valid amount</span>
<span class="success" style="display:none"> Bid submitted</span>
</form>
</div>
</div>
</body>
</html>