var head = $j('head').get(0);
var script = document.createElement('script');
script.src = _tokenScriptSrc+'&num='+_cnt++; // Add uniqueness to the script so we don't get a cached version
script.type = 'text/javascript';
script.id=kTokenScriptID;
head.appendChild(script);
/*
So this becomes,
<script type="text/javascript" src="http://mydomain.com?id=5&num=5"></script>
And becomes the last element in the head.
*/

This is within a function and is called when a form is submitted.My question is how does "script.id" work into this and where would it go? Am I misunderstanding this?BTW the script id is defined as var kTokenScriptID = 'TKN'; but why is it needed?

Assigning an ID to a script tag is normally used for tempting libraries such as handlebars so the code within it can be modified or collected on the fly, in your case since you're only executing a script there is no need for it unless its been modified down the track somewhere.