SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    HTML Code:
                           	<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)
    Code:
    		$("#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

  2. #2
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 ) then everything is about the same as above but replacing var multiple = $('#multi').serializeArray();

    with

    Code:
    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

    Keith


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •