I have a form for a referral system which has two fields namely Name and email. I also have a 'refer another friend' button which allows the user to refer another friend (capped off to 11). So another Name and email field appears. Now I have also an ajax function $.post which is designed to take only one Name and email.
How do I make the ajax function work properly if there are more than one email entries (which can be different for different users). One thing I can think of is using an array after function addInput() and then passing it to ajax. Can someone help me figure this thing out?
<script>
var countBox =1;
var boxName = 0;
function addInput()
{
if(countBox<20)
{
var boxName="textBox"+countBox;
document.getElementById('responce').innerHTML+='<input name="name" size="50" class="resize" placeholder=" Name" required type="text" id="'+boxName+'" value="'+'" " />';
countBox += 1;
var boxName="textBox"+countBox;
document.getElementById('responce').innerHTML+='<br/><input name="email" size="50" class="resize" required placeholder=" Email Address" type="text" id="'+boxName+'" value="'+'" " /><br/><br/>';
countBox += 1;
}
else{
alert("Max number of referrals reached");
}
}
</script>
<script src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#emailForm').validate({
submitHandler: function() {
$.post("index1.php",{"name":$('#name').val(),"email":$('#email').val(),"userid": "<?php echo($user) ?>"},function(data) {
if(data == "Email address has already received a referral")
alert("Email address has already received a referral");
else {
count = 3 - parseInt(data)
var content = "You have "+count+" referrals left";
$('h4').html(content);
alert ("Referral sent");
}
});
}
});
});
</script>