View Full Version : Processing form throught ajax

11-22-2010, 04:36 AM
Hello, i got this code:

$(function() {
// These first three lines of code compensate for Javascript being turned on and off.
// It simply changes the submit input field from a type of "submit" to a type of "button".

var paraTag = $('input#submit').parent('p');
$(paraTag).append('<input type="button" name="submit" id="submit" value="Email Us Now!" />');

$('#main input#submit').click(function() {
$('#main').append('<img src="images/ajax-loader.gif" class="loaderIcon" alt="Loading..." />');

var name = $('input#name').val();
var email = $('input#email').val();
var comments = $('textarea#comments').val();
var phone = $('input#phone').val();

type: 'post',
url: 'mail/contact.php',
data: 'name=' + name + '&email=' + email + '&comments=' + comments + '&phone=' + phone ,

}); // end ajax

which i use to process a form, now my questions is:
how can i perhaps give a form an ID and give it a different url on the $.ajax variable according to the form id???

11-22-2010, 11:57 PM
I though i had it, but it did not work...
Any help on this?

11-23-2010, 01:22 AM
Something like:

var request = ($(form).id == "contact") ? "contact.php" : "form.php";
url: request

Do you want it to get the from id $('input#submit') belongs to?

You can try using the .parent() (http://api.jquery.com/parent/) function in jQuery.