Jump to content

Undetermined string literal (creating a script tag with javascript) [uploadify]


joe92

Recommended Posts

I am trying to create 3 elements on the fly when a button is clicked. The button is the show an upload form for images. I am using uploadify (first time using it) and I have several different upload type/options for them so I am sending id's to differentiate between them. The problem I am having is when trying to create the script tag which in turn controls the input file type tag, and it is baffling me. Here's the code first:

var scriptContent = "$(document).ready(function() {
   $('#"+newid+"').uploadify({
   'uploader' : 'uploadify/uploadify.swf',
   'script' : '?ajax=uploadElement&id="+newid+"&updateValue=Image&inputType=image',
   'cancelImg' : 'uploadify/cancel.png',
   'folder' : 'uploads',
   'auto' : false,
   'multi' : false,
   'onAllComplete' : function(event,data) {alert(data.filesUploaded + ' files uploaded successfully!');}
   });
}); ";
var scriptTag = document.createElement('script');
scriptTag.innerHTML = scriptContent;

 

And this is the error:

unterminated string literal
[break On This Error] 	

var scriptContent = "$(document).ready(function() {
--------------------^

 

And this is what JSLint says about it:

Error:

Problem at line 1 character 21: Unclosed string.

var scriptContent = "$(document).ready(function() {

Problem at line 1 character 21: Stopping. (10% scanned).

 

The error would indicate there is something wrong with the string. First thing that came to mind was that because there is a $ sign the string was searching for a variable (even if it is within a js file) so I changed the opening and closing speech marks to single quotations and cancelled the others with backslashes. This made no difference and gave me the same error, instead pointing to a single quotation instead of a speech mark. I then tried just removing the dollar signs altogether, no difference. So I undid all of that and moved the string into a variable before the scriptTag variable is created (beforehand was just placing it straight into the innerHTML) thinking maybe I should reference the content. That didn't work either. I am at loss here and I have no idea what is wrong with that string.

 

Can you see anything wrong with it? Am I going about this the wrong way? I have multiple upload forms on the same screen because I wish for the user to be able to handle each image individually. I only want new upload forms to be shown when asked for.

 

Any help is greatly appreciated,

Joe

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.