I'm missing something in my code. I have a list of text boxes that are meant for percentage values, and there could be numerous inputs.
// loop through unknown inputs with different values
<input name="DESIREDPERCENT[<?php echo $recid; ?>]" class="percinputbox" />
// end loop
// attach click event to this element
<span id="updatepercs">Update Percentages</span>
I then have a simple span element to send all the inputs with the class percinputbox
$(document).ready(function(){
$('#updatepercs').click(function(){
var allinputs = $("input.percinputbox").serialize();
console.log(allinputs); //DESIREDPERCENT%5B73%5D=50.00&DESIREDPERCENT%5B104%5D=50.00
$.ajax({
url:'update.php',
data:"formId=updatepercentages" + allinputs,
success:function(response){ alert(response); }
});
});
I have my php listening for the $.ajax:
update.php
<?php
if($_POST['formId'] == 'updatepercentages'){
foreach( $_REQUEST['DESIREDPERCENT'] as $key ){
echo $key;
}
}
?>
So far I'm only getting one input value. So I'm definitely doing the sending wrong.
I'm open to a better/optimized way here. I generally use the <form> tag to submit forms, but I want to know how to submit these inputs with jquery.