SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pass array through jQuery

    Hi Guys!

    I have a contact form that uses jQuery. What I need is a way of passing an array through jQuery. The form can be found here:

    http://www.gasinhand.com/booking.htm

    As you can see, I have form arrays setup (the two sets of checkboxes). What I basically need to do is pass this info through jQuery. I can do the rest using PHP.

    The jQuery function I am using is here:

    Code:
    jQuery(document).ready(function(){
    	
    	$('#contactform').submit(function(){
    	
    		var action = $(this).attr('action');
    		
    		$('#contactform #submit').attr('disabled','disabled');
    		
    		$("#message").slideUp(450,function() {
    		$('#message').hide();			
    		
    		$.post(action, { 
    			mode: $('#mode').val(),
    			your_name: $('#your_name').val(),
    			tel: $('#tel').val(),
    			email: $('#email').val(),
    			helpwith: $('#helpwith').val(),
    			besttime: $('#besttime').val(),
    			comments: $('#comments').val(),
    		},
    			function(data){
    				document.getElementById('message').innerHTML = data;
    				$('#message').slideDown('slow');
    				$('#contactform #submit').attr('disabled',''); 
    				if(data.match('success') != null) $('#contactform').slideUp('slow');
    				
    			}
    		);
    		
    		});
    		
    		return false; 
    	
    	});
    	
    });
    Any ideas?

    Thanks.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Zaggs View Post
    What I basically need to do is pass this info through jQuery.
    The main problem is that you're trying to do everything with identifiers. Did you know that identifiers must be unique?

    Here is how you post your form.
    You place a form tag around the contents of your form, then you serialize the contents and post it.

    Code javascript:
    $.post(action, $("#contactform").serialize(),
        function (data) {
            ...
        }
    );

    You will need to fix up the structure of your HTML code though. Currently web browsers are ignoring your form tag because its start and end tags don't properly enclose all of their contents. As a result, undefined behaviour occurs in web browser with your form tag. Some might ignore it completely, whereas others might try and interpret things in a different way.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    The main problem is that you're trying to do everything with identifiers. Did you know that identifiers must be unique?

    Here is how you post your form.
    You place a form tag around the contents of your form, then you serialize the contents and post it.

    Code javascript:
    $.post(action, $("#contactform").serialize(),
        function (data) {
            ...
        }
    );

    You will need to fix up the structure of your HTML code though. Currently web browsers are ignoring your form tag because its start and end tags don't properly enclose all of their contents. As a result, undefined behaviour occurs in web browser with your form tag. Some might ignore it completely, whereas others might try and interpret things in a different way.
    Thanks for your reply.

    Unfortunately, I don't have a clue when it comes to Javascript/jQuery (i'm a PHP developer). Would you be able to fix this up for me (paid of course)?

    Thanks in advance.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Zaggs View Post
    Thanks for your reply.

    Unfortunately, I don't have a clue when it comes to Javascript/jQuery (i'm a PHP developer). Would you be able to fix this up for me (paid of course)?

    Thanks in advance.
    Yes, I'll do what I can to help.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •