View Single Post
Old 02-18-2013, 09:09 PM   PM User | #1
searls03
New Coder

 
Join Date: Jun 2011
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
searls03 is an unknown quantity at this point
Form a Javascript array and submit to php

I am trying to form a form that has one field that will be an array because there are multiple fields with the same name and id that will be generated from it.
PHP Code:
<form class="responseForm"  action="javascript:parseResponse123<?php echo $id?>()" id="responseForm<?php echo $id?>"> <input name="hiddenField5<?php echo $id?>" id="hiddenField5<?php echo $id?>" type="hidden" value="<?php echo $id?>" />
<input name="hiddenField4<?php echo $id?>" type="hidden" id="hiddenField4<?php echo $id?>" value="<?php echo $qty?>" />

<font color="red"><?php echo $val?></font><br />
<?php
$i
=1;
while(
$i<=$qty)
  {
?>
Participant <?php echo $i?>:<input name="hiddenField2<?php echo $id?>[]" id="hiddenField2<?php echo $id?>[]" type="text" /><br />
<?php  $i++;
  }
  
?>
 <input name="submit" type="submit" value="Submit" />
</form>
Then I want to use javascript to form the array for the hiddenfield2 parameter and use this code to submit to insert.php

Code:
<script type="text/javascript">
function parseResponse123<?php echo $id; ?> () 
{
	var hiddenField2<?php echo $id; ?> = $("#hiddenField2<?php echo $id; ?>");
	var hiddenField4<?php echo $id; ?> = $("#hiddenField4<?php echo $id; ?>");
	var hiddenField5<?php echo $id; ?> = $("#hiddenField5<?php echo $id; ?>");
	var hiddenField1<?php echo $id; ?> = $("#hiddenField1<?php echo $id; ?>");

	var url = "insert.php";
	
		$.post(url,{  hiddenField2[]: hiddenField2<?php echo $id; ?>.val(),hiddenField: hiddenField5<?php echo $id; ?>.val(), hiddenField1:hiddenField1<?php echo $id; ?>.val(), hiddenField4:hiddenField4<?php echo $id; ?>.val()  } , 
		function(data) {
	
		});
		setTimeout(function() {

		$.ajax({
		type:"POST",
		data:"getNews=true",
		success: function(r){
			$("#newsContent").html(r);
			
		},
		error: function(){
alert($(".hiddenField2<?php echo $id; ?>").val());		
	$("#error").text($(".hiddenField2<?php echo $id; ?>")).fadeIn(300)
		}
	})


	},200);
}

</script> 
<?php
then decode the array using php(I have not gotten this far as I haven't been able to submit any formed array)


any help from anyone?
searls03 is offline   Reply With Quote