jQuery form array, passing values

Hi Good people.

I have searched and cant find an answer to this specific jQuery problem.

I have a form which when submitted takes the ID values of the form fields and passes via GET to a php file which does a search in a database and returns results.

The issue that I ahve is that one of the fields is an array as follows


                       	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="John" align="absmiddle" /><label for="multi[]">John</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Daniel" align="absmiddle" /><label for="multi[]">Daniel</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Jane" align="absmiddle" /><label for="multi[]">Jane</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Gemma" align="absmiddle" /><label for="multi[]">Gemma</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Kev" align="absmiddle" /><label for="multi[]">Kev</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Kelly" align="absmiddle" /><label for="multi[]">Kelly</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Simon" align="absmiddle" /><label for="multi[]">Simon</label>
                </div>
                        	<div class="name_box">
                <input name="multi[]" id="multi[]" type="checkbox" value="Olive" align="absmiddle" /><label for="multi[]">Olive</label>
                </div>

What I need to do is be able to pass the multi array to the php file via “get” as opposed to “post” is a datastring. And its driving me nuts.

The jQuery looks like this (cut down version)


		$("#find_host").click(function(){		
				var ckbCheckAll = $('#ckbCheckAll').val();
				var sortresult = $('#sortresult').val();
				var multiple = $('#multi').serializeArray();
				var dataString = "ckbCheckAll+"&sortresult="+sortresult+"&multiple="+multiple;
				
				  if(no_nights.length>0){ // this is just a condition on a bit of data i havnt included
						$.ajax({
							  type: "GET",
							  url: "includes/file.php",
							  data: dataString,
							  success: function(server_response){
								$('#host_result').html(server_response).show();
							  }
						});
				  }return false;


Can anyone put me out of my misery please

Thanks in advance

Keith

Solved it.

Im sure its not as pretty as some of you could make it but it works

First I removed the id=“multi” as id’s should be unique (bad boy :slight_smile: ) then everything is about the same as above but replacing var multiple = $(‘#multi’).serializeArray();

with



var multi_members = '';
				
$("input[name='multi[]']:checked:enabled").each(function() {
    	multi_members=multi_members+","+$(this).val();
});


This puts a comma between each value which is passed as a “get” method to the waiting .php file. Sorted.

Hope that helps someone in the future or points them in the right direction.

Guru’s, feel free to pull it to bits :slight_smile:

Keith