Why does javascript sometimes output undefined variable
<p>I have a small button which when pressed asks for a name and then adds the input to the URL which can then be processed by PHP. My code is below.</p>

<pre><code>    function staff_prompt(url)
  {
  var url = url;
  var staffname=prompt("Please enter your Name below:","Staff Member Name");
  if (staffname == null)  {
  } 
  else if (staffname == "Staff Member Name") {
  alert('You must enter a value to continue');
  staff_prompt();
  }
  else if (staffname == "") {
  alert('You must enter a value to continue');
  staff_prompt();
  }
  else {
  var windowgo = url + "&amp;staffmember=" + staffname;
  window.location = windowgo;
 }
 } 
</code></pre>

<p>My Button code is below</p>

<pre><code>onclick="staff_prompt('index.php?app=orders&amp;page=action&amp;action=go_orderedviewtype=&lt;?php echo $viewtype ?&gt;&amp;orderid=&lt;?php echo $orderid ?&gt;') 
</code></pre>

<p>Sometimes it works well, however other times it seems to go to "http://undefined....ect"
I cannot replicate the situation, sometimes it happens and sometimes not</p>

<p>I am thinking that maybe the code is not very good... why would the javascript not detect sometimes the variable 'url'.</p>
