/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] jquery get input name and pass to php script

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”>[/CODE]

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;
});
});[/CODE]

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);
}[/CODE]

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@bizkit1authorMar 22.2012 — SOLVED.

[CODE]var entry = $('input[name="entry\[\]"]').map(function(){
return this.value;
}).get();[/CODE]
×

Success!

Help @bizkit1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...