0

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

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by scarcella
0

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; 
	
	});
0

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

Thanks,
Marais

Edited by scarcella: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.