Hi guys i was wondering if you guys could let me know how i can post a form field using jquery and then be declared in a variable after post.

The code for the html:

<table cellpadding="0" cellspacing="0">
            <tr>
        		<td></td>
                <td>Name:</td>
                <td>Email:</td>
            </tr>
            <tr>
            	<td><label for=fri accesskey=f>Friend 1</label></td>
                <td class="tablePadding"><input name="friname[]" type="text" id="friname" class="friname" size="25" value="" /></td>
                <td><input name="friemail[]" type="text" id="friemail" class="friemail" size="25" value="" /></td>
            </tr>
            <tr>
            	<td><label for=fri accesskey=f>Friend 2</label></td>
                <td class="tablePadding"><input name="friname[]" type="text" id="friname" class="friname" size="25" value="" /></td>
                <td><input name="friemail[]" type="text" id="friemail" class="friemail" size="25" value="" /></td>
            </tr>
            <tr>
            	<td><label for=fri accesskey=f>Friend 3</label></td>
                <td class="tablePadding"><input name="friname[]" type="text" id="friname" class="friname" size="25" value="" /></td>
                <td><input name="friemail[]" type="text" id="friemail" class="friemail" size="25" value="" /></td>
            </tr>
            </table>

It gets posted to contact.php

here is the php contact.php file

$friname    = $_POST['friname'];
	
	foreach ($friname as $item) {
		print $item."<br>";	
	}

Here is the jquery for the post

$('#contactform').submit(function(){
	
		var action = $(this).attr('action');
		
		$("#message").slideUp(750,function() {
		$('#message').hide();			
		
		
		$.post(action, { 
			name: $('#name').val(),
			email: $('#email').val(),
			friname: $('#contactform input[name="friname[]"]').val(),
			friemail: $('.friemail').val(),
			comments: $('#comments').val(),
			verify: $('#verify').val()
		},
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()}); 
				if(data.match('success') != null) $('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});

Thank you if you guys can help.

Thanks,
Marais

are you having trouble sending/submitting all the fields? If so, try:

$('#contactform').submit(function(){
	
		var action = $(this).attr('action');
		
		$("#message").slideUp(750,function() {
		$('#message').hide();			
		
		// http://api.jquery.com/serialize/
		$.post(action, $('#contactform').serialize(),
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()}); 
				if(data.match('success') != null) $('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});

thanks you soo much, that really helped. As you can tell im a php coder not a jquery coder. HEHE

Thanks,
Marais

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.