Reputation: 41
I want to upload multiple file with title and link. i am getting following error
invalid property id
$('#divUpload').uploadifySettings('scriptData',{,'txttitle1':'Title1','tbxLink1':'Link1','1':'image1.PNG'},'1');
My code is like this :
<script type="text/javascript" language="javascript">
var divMsg ='<%= divMsg.ClientID %>';
var errcnt=0;
$(document).ready(function() {
$('#divUpload').uploadify({
'uploader': WebSiteUrl + 'admin/fileupload/uploadify.swf',
'script': WebSiteUrl + 'admin/banner-image-upload.aspx?type=fileupload',
'multi' : 'true',
'method' : 'POST',
'cancelImg' : WebSiteUrl + 'admin/images/cancel.png',
'folder': '../source/BannerImage',
'queueSizeLimit' : '20',
'fileDesc' : '*.JPEG;*.JPG;*.GIF;*.PNG;*.BMP',
'fileExt': '*.JPEG;*.JPG;*.GIF;*.PNG;*.BMP',
'wmode' : 'transparent',
'onCancel':function(event,queueID,fileObj,data){if(data['fileCount']==0){txtboxIndex=0;$('#btnUploadfile').hide();}else{txtboxIndex=txtboxIndex-1;}},
'onAllComplete': function(event,data)
{
if(errcnt==0)
{
window.opener.location.href =WebSiteUrl + 'admin/home-banner-list.aspx?mode=uploadsucc';
window.close();
}
},
'onSelect' : function(event,queueid,fileObj){$('#btnUploadfile').show();},
'onComplete': function(event,queueID,fileObj,response,data){if(response=='maxupload')errcnt++;}})
});
function UploadFiles()
{
var cnt='';
var str='';
var strLink='';
$('.txttitle').each(function(index){
if(jQuery.trim($(this).val())=='')
{
if(cnt.length ==0)
cnt=(index + 1);
else
cnt=cnt + ',' +(index + 1);
}
});
if(cnt.length!=0)
{
alert('Please insert title in photo#' + cnt);
return false;
}
$('.txttitle').each(function(index){
cnt= $(this).attr('name').replace('txttitle','');
str =str + ',\'' + $(this).attr('name') + '\':\'' + $(this).val() + '\'';
str =str + ',\'' + $('.tbxLink').attr('name') + '\':\'' + $('.tbxLink').val() + '\'';
str= str + ',\'' + cnt + '\':\'' + $('#hdnfile'+ cnt).val() + '\'';
});
str='{' + str + '}';
alert(str);
eval('$(\'#divUpload\').uploadifySettings(\'scriptData\',' + str +');');
$('#divUpload').uploadifyUpload();
}
</script>
Upvotes: 0
Views: 255
Reputation: 630399
You're generating invalid code, like this:
$('#divUpload').uploadifySettings('scriptData',{,'txttitle1':'Title1','tbxLink1':'Link1','1':'image1.PNG'},'1');
^ invalid comma
But...it's better not to use eval()
at all, you can construct your data object with bracket notation, like this:
var data = {};
$('.txttitle').each(function() {
data[this.name] = this.value;
data[$('.tbxLink').attr('name')] = $('.tbxLink').val();
data[cnt] = $('#hdnfile'+ this.name.replace('txttitle','')).val();
});
$('#divUpload').uploadifySettings('scriptData',data);
Granted that's the literal translation of what you're trying to do...this still isn't optimal, especially the $('.tbxLink').attr('name')
line, since you're likely wanting the .tbxLink
that relates to this .txttitle
element you're on, but without seeing the markup I can't say exactly what that should look like.
Upvotes: 1