SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Simple id question

    Hi all, I have this code to work with,
    Code:
     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?

    Thanks in advance,
    Loren.
    What I lack in acuracy I make up for in misteaks

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would guess it's to allow the script to identify the script block that loaded it.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •