title: Javascript: Can't pass variables as parameters with onClick
body: <p>I have this code (jquery):</p>
  
  <pre><code>function somefunction() {
  
          $.ajax({
          type : 'POST',
          url : 'post.php',
          dataType : 'json',
  
          success : function(data){
  
              var mess = "";  
              var count = 0;
  
              while (count &lt; (data.length - 1))
              {
  
                   mess = mess + "&lt;a href=# onclick=deletePerson("JohnDoe");return false;&gt;&lt;img src=x.gif&gt;&lt;/a&gt;" + data[count].name + "&lt;br /&gt;";
                   count++;
              }
  
  
              $('#mydiv').html(mess).fadeIn('fast');
  
  
          },
      });
  
  
  }
  function deletePerson(arg) {...}
  </code></pre>
  
  <p>When I run this, everything works fine.
  However, when I want to pass a variable (instead of "JohnDoe") with the onclick, it stops working:</p>
  
  <pre><code>var myvar = "JohnDoe";
  mess = mess + "&lt;a href=# onclick=delete(myvar);return false;&gt;&lt;img src=x.gif&gt;&lt;/a&gt;" + data[count].name + "&lt;br /&gt;";
  </code></pre>
  
  <p>My editor tells me: "Unresolved variable or type".</p>
  
  <p>Never had a problem with passing parameters, but with this onClick-thing it just doesn't work...</p>
  
  <p>Anyone knows what I'm doing wrong?</p>
  
  <p>Thank's a lot!</p>
  
  <p>EDIT: Joseph's post fixed the JohnDoe problem (thanks!), however, when I put:</p>
  
  <pre><code>var myvar = data[count].name;
  </code></pre>
  
  <p>it stops working... any thoughts?</p>