title: Uncaught ReferenceError: variable is not defined on onclick function Javascript
body: <p>Today , i have been read all the topic about this but couldn't come up with a solution that's why i am opening this topic.</p>
  
  <p>This is my function which creates the view and i am trying to have a onclick function which should directs to other javascript function where i change the textbox value.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $('#submitbtnamazon')
              .click(function(evt) {
                          var x = document.getElementById("term").value;
  
                          if (x == null || x == "" || x == "Enter Search Term") {
                              alert("Please, Enter The Search Term");
                              return false;
                          }
                          listItems = $('#trackList').find('ul').remove();
                          var searchTerm = $("#term").val();
                          var url = "clientid=Shazam&amp;field-keywords="
                                  + searchTerm
                                  + "&amp;type=TRACK&amp;pagenumber=1&amp;ie=UTF8";       
  
      jsRoutes.controllers.AmazonSearchController.amazonSearch(url)
                          .ajax({
                              success : function(xml) {
                                  $('#trackList')
                                      .append('&lt;ul data-role="listview"&gt;&lt;/ul&gt;');
                                      listItems = $('#trackList').find('ul');
                                      html = ''
  
                                   tracks = xml.getElementsByTagName("track");
                                  for(var i = 0; i &lt; tracks.length; i++) {
                                      var track = tracks[i];
                                      var titles = track.getElementsByTagName("title");
                                      var artists = track.getElementsByTagName("creator");
                                      var albums =    track.getElementsByTagName("album");
                                      var images =    track.getElementsByTagName("image");
                                      var metaNodes = track.getElementsByTagName("meta");
                                       //trackId ="not found";
  
                                       trackIds = [];
                                                      for (var x = 0; x &lt; metaNodes.length; x++) {
                                                          var name = metaNodes[x]
                                                                  .getAttribute("rel");
  
                                                          if (name == "http://www.amazon.com/dmusic/ASIN") {
                                                              trackId = metaNodes[x].textContent;
                                                              trackIds.push(trackId);
  
                                                          }
                                                      }
  
                                                      for (var j = 0; j &lt; titles.length; j++) {
                                                          var trackId=trackIds[j];
                                                          html += '&lt;div class="span3"&gt;'
                                                          html += '&lt;img src="' + images[j].childNodes[0].nodeValue + '"/&gt;';
                                                          html += '&lt;h6&gt;&lt;a href="#" onclick="someFunction('
                                                              +trackId
                                                              + ')"&gt;'
                                                              +trackId
                                                              + '&lt;/a&gt;&lt;/h6&gt;';
                                                          html += '&lt;p&gt;&lt;Strong&gt;From Album:&lt;/strong&gt;'
                                                                  + albums[j].childNodes[0].nodeValue
                                                                  + '&lt;/p&gt;';
                                                          html += '&lt;p&gt;&lt;Strong&gt;Artist Name:&lt;/strong&gt;'
                                                                  + artists[j].childNodes[0].nodeValue
                                                                  + '&lt;/p&gt;';
                                                          html += '&lt;p&gt;&lt;Strong&gt;Title:&lt;/strong&gt;'
                                                                  + titles[j].childNodes[0].nodeValue
                                                                  + '&lt;/p&gt;';
                                                          /*html += '&lt;p&gt;&lt;Strong&gt;Created:&lt;/strong&gt;'
                                                                  + releaseDate
                                                                  + '&lt;/p&gt;';*/
                                                          html += '&lt;/div&gt;'
                                                      }
                                                  }
                                                  //listItems.append( html );
                                                  $("#track").html(html);
                                                  $("#track").dialog({
                                                      height : 'auto',
                                                      width : 'auto',
                                                      title : "Search Results"
                                                  });
                                                  // Need to refresh list after AJAX call
                                                  $('#trackList ul').listview(
                                                          "refresh");
                                              }
                                          });
                      });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is my other function where i change the textbox value. it works actually with other values e.g. when i give hardcoded string value. I can see the value in the console but for some reason it gives me the error like :
  here the string starts with B is AsinId where i take from amazon. I am definitely in need of help because i am totally stucked.</p>
  
  <p>Uncaught ReferenceError: B00BMQRILU is not defined 62594001:1 onclick</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      function someFunction(var1) {
          tracktextbox = document.getElementsByName("trackId");
          for (var i = 0; i &lt; tracktextbox.length; i++) {
              tracktextbox[i].value = var1;
          }
          $('#track').dialog('close');
      }
  
  &lt;/script&gt;
  </code></pre>