Hello guys. I have a form with some dynamically generated input fields based on the numeber of month between 2 dates. So if the number of months is 5 i would have something like this:
[CODE]<input name=”entry[]” type=”text”>
<input name=”entry[]” type=”text”>
<input name=”entry[]” type=”text”>
<input name=”entry[]” type=”text”>
<input name=”entry[]” type=”text”>
When i submit the form it uses a jquery like this one:
[CODE]$(function() { // Shorthand for $(document).ready(function() {
$(‘#insertctr’).click(function() {
var contractid=$(“#contractid”).val();
var tipctr=$(“#tipctr”).val();
var partener=$(“#partener”).val();
var oras=$(“#oras”).val();
var status=$(“#status”).val();
var obs=$(“#obs”).val();
var datastart=$(“#datastart”).val();
var dataend=$(“#dataend”).val();
var sumatotala=$(“#sumatotala”).val();
var vsumatotala=$(“#vsumatotala”).val();
var sumalunara=$(“#sumalunara”).val();
var vsumalunara=$(“#vsumalunara”).val();
var curs=$(“#curs”).val();
var obiect=$(“#obiect”).val();
var contact=$(“#contact”).val();
var sold=$(“#sold”).val();
var confidential=$(“#confidential”).val();
if (tipctr && partener && oras && status && datastart && dataend && sumatotala && sumalunara && sold) {
$.post(‘addtodbt.php’, {contractid: contractid, tipctr: tipctr, partener: partener, oras: oras, status: status, obs: obs, datastart: datastart, dataend: dataend, sumatotala: sumatotala, vsumatotala: vsumatotala, sumalunara: sumalunara, vsumalunara: vsumalunara, curs: curs, obiect: obiect, contact: contact, sold: sold, confidential: confidential},
function(data){
$(“#message”).html(data);
$(“#message”).hide();
$(“#message”).fadeIn(1500);
});
}
else {
alert(‘All fields are mandatory!’);
}
return false;
});
});
I want to pass the data from the input fields with the name entry[] through this jquery script to a php script that will add it all to the mysql db. Here is the php code that ads the input entry[] to db:
[CODE]$name = $_POST[‘entry’];
$i=0;
$numelentos = count($name);
for ($i=0; $i < $numelentos; $i++)
{
$query2=”INSERT INTO test(id_contract,ceva) VALUES (‘$ctrfull’,’$name[$i]’)”;
mysql_query($query2);
}
The problem is that i don`t know how to write jquery code to get al the entry[] data and pass it to the php. If i do this without jquery and call the php script directly using a form it works, but i need to add through the jquery. Please help me