I'd like to put a javascript variable value dynamically inside to a script src url.
<head runat="server">
<script type="text/javascript">
var id = $("[id$='hfProductIdList']").val();
</script>
<script type="text/javascript" src="https://test/tr.aspx?orderid=id">
</script>
</head>
If there is a way to set up these value dynamicly It would be great for me.
I'd like to put a javascript variable value dynamically inside to a script src url.
<head runat="server">
<script type="text/javascript">
var id = $("[id$='hfProductIdList']").val();
</script>
<script type="text/javascript" src="https://test/tr.aspx?orderid=id">
</script>
</head>
If there is a way to set up these value dynamicly It would be great for me.
Share Improve this question edited May 9, 2013 at 8:41 baros asked May 9, 2013 at 8:35 barosbaros 2512 gold badges9 silver badges23 bronze badges 1- what are you trying to do here? if you want to send file to server side script (in this case asp) use ajax. you are giving asp page as source where it is expected js (because you use type = javascript) – Bojan Kovacevic Commented May 9, 2013 at 8:39
2 Answers
Reset to default 4You can simply do this:
var id = $("[id$='hfProductIdList']").val();
$('head').append('<script type="text/javascript" src="https://test/tr.aspx?orderid=' + id + '" />');
You need to append it using pure javasript;
var id = $("[id$='hfProductIdList']").val();
var jsElem = window.document.createElement('script');
jsElem.src = 'https://test/tr.aspx?orderid=' + id;
jsElem.type = 'text/javascript';
$('head').append(jsElem);
Also it might be better idea to append it to body rahter than head, but it's not a subject of your question.