INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How do I access form data from a JQuery form object?

How do I access form data from a JQuery form object?

(OP)
I have an on.submit handler, which I assume is being passed the form to $(this), how do I access the form data?

CODE

$('#financial_promotion').on('submit',function(e) {
        e.preventDefault();
        showDialog('We are processing your financial promotion.','Please Wait!',[]); 
        sendFP($(this));   
    }); 

OK, but now what?

CODE

// Send FP form
function sendFP(frm)
{
    frm.????
} 

I'm obviously missing something real simple, but I can't work it out.

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: How do I access form data from a JQuery form object?

CODE

$('#financial_promotion').on('submit',function(e) {
        e.preventDefault();
        var frmObj = $(this).get(0);
        var formData = new FormData(frmObj);
        $.ajax( {....} );  
    }); 

RE: How do I access form data from a JQuery form object?

What do you want to do with the form data?

If you submit the form to the server, you would need a server side script to process that data. Usually inside the POST variable.

If you want to access it from jquery you can target the form elements individually to get their contents.

Something like:

CODE

alert(frm.elements.elementName.value); 

that would theoretically alert the value of an element such as an input.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: How do I access form data from a JQuery form object?

(OP)
Justin is close to what I'm trying to achieve (I think), this is what I have...

CODE

// Send FP form
function sendForm(frm)
{

    // create formdata object from form
    var data = new FormData(frm);
    
    // check if filereader shim used and manually add file if there is one
    if(!$('#fp_file').val() && myFile)
    {
        data.append('fp_file', myFile, myFile.name);
    }

    $.ajax({
        url: frm.attr('action'),  // server script to process data
        type: 'POST',
        xhr: function() {  // custom xhr
            var myXhr = $.ajaxSettings.xhr();
            if(myXhr.upload){ // check if upload property exists
                myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
            }
            return myXhr;
        },
        data: data, 
        cache: false,
        contentType: false,
        processData: false
    });

} 

This is a far as I have got, I've yet to implement the progress meter with the <progress> element let alone see if I can actually read the form data and file server side.

I'll look at this again Monday, not finding this fun at all, so gonna do some painting this weekend instead of coding.

Have a great weekend guys and gals.

1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: How do I access form data from a JQuery form object?

if you're going to upload files you need to set the contentType to multipart/form-data too.

i think if you want to add a binary file something like this would be more likely

CODE

data.append("myFile", $('#fp_file').get(0).files[0]); 

RE: How do I access form data from a JQuery form object?

(OP)

Quote:

if you're going to upload files you need to set the contentType to multipart/form-data too.
Not according to all the information I can find on this. Everything I have found says you MUST set it to 'false' for this to work.

I should have a handle on this today, so will let you know what I find.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close