joaocc
asked on
ajaxForm plugin - dynamic id
I am using the ajaxform plugin to upload some images, and at the same time I need to send an id to update the database.
To explain better, my files:
upload.html
The problem with this is that "data: {id:$('#selectorPubImg').v al()}, " will always be "1" since i am storing it in a document.ready(). Is there a way to update that value with the current value of the selection list?
Thank you guys
To explain better, my files:
upload.html
<form id="myForm" action="upload.php" method="post" enctype="multipart/form-data">
<select id="selectorPubImg">
<option value="1">image 1</option>
<option value="2">image 2</option>
<option value="3">image 3</option>
<option value="4">image 4</option>
</select>
<input type="file" size="60" name="myfile">
<input type="submit" value="Enviar">
</form>
my js file:$(document).ready(function()
{
var options = {
data: {id:$('#selectorPubImg').val()},
beforeSend: function()
{
$("#progress").show();
//clear everything
$("#bar").width('0%');
$("#message").html("");
$("#percent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$("#bar").width(percentComplete+'%');
$("#percent").html(percentComplete+'%');
},
success: function()
{
$("#bar").width('100%');
$("#percent").html('100%');
},
complete: function(response)
{
$("#message").html("<font color='green'>"+response.responseText+"</font>");
},
error: function()
{
$("#message").html("<font color='red'> ERROR: unable to upload files</font>");
}
};
$("#myForm").ajaxForm(options);
});
The problem with this is that "data: {id:$('#selectorPubImg').v
Thank you guys
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, it works perfect. Thanks also Julian, i used tagit version since it was the first and it worked, i am sure yours also work just fine. you guys are great. ;)
Not begrudging tagit the points but the correct way is to use the constructs that the ajaxform provides.
In this case you set the data you want to send in the beforeSubmit.
In this case you set the data you want to send in the beforeSubmit.
ASKER
thank julian, i will look into it.
I agree, my version works but Julian's is better :) It's cleaner and using it how ajaxForm was designed. If I came across this solution I would want to use his.
ASKER
When I opened the email this morning I just "copy paste" the first expert comment and it worked right way. After I saw the julian solution and to be honest I didnt try it out since the tagit solution worked so well.
Then I was told that Julian solution is the "right way" to do it, and I am sure that's true, but since tagit solution was the first one I saw...
I am totally ok of spliting the points if after my explanation moderators feel like that.
btw, Julian and tagit thank you again for the help, not only in this question but in many others.
Sorry for any inconvenience.
Then I was told that Julian solution is the "right way" to do it, and I am sure that's true, but since tagit solution was the first one I saw...
I am totally ok of spliting the points if after my explanation moderators feel like that.
btw, Julian and tagit thank you again for the help, not only in this question but in many others.
Sorry for any inconvenience.
No problem at all. Glad to help :-)
My point here was to highlight that there was another solution posted. To be honest I think if you came across this post and read to the bottom you would find this out anyway but Im just putting it out there by requesting attention to see how everyone else feels
My point here was to highlight that there was another solution posted. To be honest I think if you came across this post and read to the bottom you would find this out anyway but Im just putting it out there by requesting attention to see how everyone else feels
You are welcome - and I don't mind if you accept tagit's solution as assisted with full points and mine as accepted with 0 - don't want to make this about the points.
Just for future readers of the post I think the beforeSubmit answer should be the right one.
The stackoverflow guys are giving us stick because we don't have a rigourous system of accepting correct answers - so just trying to do my bit to keep EE on top.
@tagit - thanks for the support mate - appreciate it.
Just for future readers of the post I think the beforeSubmit answer should be the right one.
The stackoverflow guys are giving us stick because we don't have a rigourous system of accepting correct answers - so just trying to do my bit to keep EE on top.
@tagit - thanks for the support mate - appreciate it.
No problem mate. I'm all for EE and keeping it the best :-)
Open in new window