Reputation: 251
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.
Upvotes: 2
Views: 4541
Reputation: 73906
You can simply do this:
var id = $("[id$='hfProductIdList']").val();
$('head').append('<script type="text/javascript" src="https://test/tr.aspx?orderid=' + id + '" />');
Upvotes: 4
Reputation: 3401
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.
Upvotes: 2