SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question USing JQuery to get form data

    Hey there,

    I am using JQuery to get some form data. Here is the html:

    <input name="test2" type="text" value="39" size="32" maxlength="20" value=""/>

    Here is my Jquery.

    Code:
    var $inputs = $('#details :input');
    
       var values = {};
        $inputs.each(function() {
            values[this.name] = $(this).val();
            
        });
    
    $('#checkout').click(function()
    
     {
    
        $.ajax({
            type: 'GET',
            url: 'index.php?route=payment/check/confirm',
            data: {id:'test', id2:values['test1'], id3:values['test2'], id4:values['test3']},
            success: function() {
                location = '<?php echo $continue; ?>';
            }        
        });
    });
    If I hardcode a value into the html then my jquery returns and displays it correctly but if I input it manually on the page, it returns nothing.

    As you can see it uses Ajax to load another script and if successful, completes the transaction. However, it refuses to accept my manually input values. Is this because I haven't used a submit button? I haven't even declared a form action or method because I am using the onclick event handler and using Jquery to get everything from the form. This is not my design, it is the cms system I am working with.

    Can anyone suggest a workaround?

  2. #2
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [SOLVED]

    mY JQuery to select the input values was outside of the click function so I moved it inside and now its fine

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    jQuery.serializeArray() is what you should use if your posting form values
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle


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
  •