views:

1393

answers:

3

Is it possible to submit FORM DIV elements (NOT Form) using jquery/ajax? I know of multiple was you can use jquery.form.js and jquery.upload.js. But they don't meet my requirements.

I have the following HTML within my ASCX control (within my ASPX master page that already has a FORM tag)

<div id="Div1">
    File: <input type="file" id="fileName"/><br/>
    Tags: <input type="text" id="fileTags"/><br/>
    <input type="submit" value="Submit File"/>
</div>

My question is: I want to submit only the two elements (fileName and fileTags) in this DIV and not the whole ASPX form. Is there a jquery script/plugin that I can use to submit this DIV's element to the server without refreshing the page? e.g.

$("Div1").ajaxSubmit();

Without having to recreate the wheel.

A: 

<input> isn't even valid without a <form>

tliff
If you read the question you will have noticed that it is in a MASTER PAGE that already has a FORM element
Tawani
you realise that the contents of a slave page will be within the masters form?
annakata
+1  A: 

You can use jQuery to walk the HTML, and dynamically create an object to be submitted:

var obj = { filename: $('#filename').val(), fileTags: $('#fileTags').val() };
$.post('url.aspx', obj, myCallbackFunction);

That will send obj as a POST to your server. Your server side code can access the fileTags via Request.Form["fileTags"]

However I do not think that will work on a file upload control.

swilliams
I think the OP is tying himself in knots and there is no way to do whatever it is he wants to do, but this should at least be educational
annakata
Agreed. I use what I wrote often enough, but never with a file upload. Maybe something like Flash or Silverlight might be a valid option?
swilliams
A: 

It might help if you could explain why you want to do this, since it seems like you must have an unusual situation if this is the best solution.

Jeremy Banks