title: Javascript - Set source file and assigning value to a control
body: <p>I have a tree view control build dynamically.  i want to change color of the selected node 
   .one help me to write the script given below. and its work fine.</p>
  
  <pre><code> &lt;script type="text/javascript"  src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      google.load("jquery", "1.4.2");
      google.setOnLoadCallback(function() {
          //change cursor to hand when user mouseover tree nodes
          $(".TreeView1_0").mouseover(function() {
              $(this).css('cursor', 'pointer');
          });
  
  
          //unbold all nodes then bold the selected node to indicate it's selected
          $(".TreeView1_0").click(function() {
              $(".TreeView1_0").css('font-weight', 'normal');
              $(".TreeView1_0").css('color', 'black');
              $(".TreeView1_0").css('background-color', 'white');
  
  
              $(this).css('color', 'white');
  
              $(this).css("background-color", "blue");
  
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Now i want to change the source file to the js file stored in script folder.And  store selected node index and value in hidden fields.i have a source file JQuery1.4.1.js in script folder. i dont know what is the exact way of referencing to this js file. and i dont know how to retrieve selected node index and value </p>
  
  <p>i changed the code to do that.the entire aspx code is shown below</p>
  
  <p>&lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></p>
  
  <p>&lt;html xmlns="http://www.w3.org/1999/xhtml">
  &lt;head id="Head1" runat="server">
      &lt;title>&lt;/title></p>
  
  <pre><code>   &lt;script type="text/javascript" src="../../Scripts/JQuery1.4.1.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
  
  
          //change cursor to hand when user mouseover tree nodes
          $(".TreeView1_0").mouseover(function() {
              $(this).css('cursor', 'pointer');
          });
  
  
          //unbold all nodes ,then bold the selected node to indicate it's selected ,and store  selected node index and value to two hidden fields
          $(".TreeView1_0").click(function() {
              $(".TreeView1_0").css('font-weight', 'normal');
              $(".TreeView1_0").css('color', 'black');
              $(".TreeView1_0").css('background-color', 'white');
              $(this).css('color', 'white');
              $(this).css("background-color", "blue");
  
            // i am not sure about the two lines of code given below
              document.getElementById('hfvalue').value = $(this).value;
              document.getElementById('hfindex').value =$(this).index;
  
              $(this).css('color', 'white');
  
              $(this).css("background-color", "blue");
  
          });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>&lt;/head></p>
  
  <p>&lt;body></p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &lt;asp:TreeView ID="TreeView1" runat="server"&gt;
      &lt;/asp:TreeView&gt;
  &lt;/div&gt;
  &lt;p&gt;
      &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /&gt;
      &lt;asp:HiddenField ID="hfvalue" runat="server" /&gt;
      &lt;asp:HiddenField ID="hfindex" runat="server" /&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>&lt;/body>
  &lt;/html></p>
  
  <p>But the code is not working . i am a newbie. Any suggestions</p>