joe92 Posted December 23, 2011 Share Posted December 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253753-undetermined-string-literal-creating-a-script-tag-with-javascript-uploadify/ Share on other sites More sharing options...
joe92 Posted December 23, 2011 Author Share Posted December 23, 2011 The new lines were causing an error. Didn't realise that javascript didn't allow new lines in a string. Sorted now. Quote Link to comment https://forums.phpfreaks.com/topic/253753-undetermined-string-literal-creating-a-script-tag-with-javascript-uploadify/#findComment-1300868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.