Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i want to add a javascript file in aspx page <head> section, but this javascript file name changes dynamically. Can i use a variable for src attribute in script element as shown in below example

e.g:

var jsFileName = "JScript1"`
<script type="text/javascript" src="jsFolder/' + jsFileName + '.js"></script>

this is not working for me. Any help is appreciated.

share|improve this question
what is the case when jsFolder/JScript1.js, is the file loaded? – Ashok Sep 27 at 9:24

2 Answers

Try this rather than setting it to a javascript variable jsFileName

<script type="text/javascript" src="jsFolder/<%= ServerSideVariable %>.js"></script>

Hope you can do this way

share|improve this answer

Can you try this

var fileName = "jsFolder/" + jsFileName + ".js";
document.write("<script type=\"text/javascript\" src=\"" + fileName + "\"></script>");
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.