0

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.

1 Answer 1

1

You are missing an & between formId=updatepercentages and allinputs

data:"formId=updatepercentages&" + allinputs,

Sign up to request clarification or add additional context in comments.

1 Comment

Mother Of Pearl!! I knew it was something mundane!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.