Hi, I was trying to do this with prototype instead but can’t get it to work. I’ve now gone back to trying Jquery to solve the problem.
Basically I have a PHP script that outputs many forms, all with inputs with the same class names. The form will be submitted through ajax to be passed to a PHP script to save it to a database.
Here is the code so far that I’m working from:
<script type="text/javascript" >
$(function() {
$(".submit").click(function() {
var para = $("#para").val();
var pass= $("#pass").val();
var dataString = 'para='+ para + '&pass=' + pass;
if(para=='' || pass=='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "../results/process.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
});
</script>
and the html
<div class="para-wrap">
<form method="post" name="form">
<textarea name="para" id="para">
Content goes here
</textarea>
<input name="pass" id="pass" type="hidden" value="Source" />
<input type="submit" value="submit" class="submit" />
<span class="error" style="display:none"> Please Enter Valid Data</span>
<span class="success" style="display:none"> Registration Successfully</span>
</form>
</div> <!--end parawrap-->
<div class="para-wrap">
<form method="post" name="form">
<textarea name="para" id="para">
Different Content
</textarea>
<input name="pass" id="pass" type="hidden" value="Source" />
<input type="submit" value="submit" class="submit" />
<span class="error" style="display:none"> Please Enter Valid Data</span>
<span class="success" style="display:none"> Registration Successfully</span>
</form>
</div> <!--end parawrap-->
Any help would really be great, thanks!