Results 1 to 3 of 3

Thread: Processing form throught ajax

  1. #1
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Processing form throught ajax

    Hello, i got this code:
    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).children('input').remove();
        $(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();
    
            $.ajax({
                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???

  2. #2
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I though i had it, but it did not work...
    Any help on this?

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Something like:
    Code:
    var request = ($(form).id == "contact") ? "contact.php" : "form.php";
    $.ajax({
    url: request
    });
    Do you want it to get the from id $('input#submit') belongs to?

    You can try using the .parent() function in jQuery.
    Last edited by Nile; 11-23-2010 at 06:44 PM.
    Jeremy | jfein.net

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
  •