passing a php array to javascript
<p>I have a php that echos html.  Inside one of these echos I have a button that calls a javascript function.  Inside of this call I pass a php variable.  However when I see what the value of one of the elements is inside of the javascript I get undefined.</p>

<p>Any ideas?</p>

<p>Javascript</p>

<pre><code>function addrow(innerid, teams){


    alert(teams[1]);}
</code></pre>

<p>Here is how I pass it, this is all inside of an echo</p>

<pre><code>&lt;input type = "button" id = '.$buttonid.'  value = "Agregar" onclick = "addrow(\'' . $leaguesarray[$numofleagues] . '\','.$teamsarray.')
</code></pre>

<p>So I call addrow(with a league value, and I also pass the array teamsarray from php</p>

<p>I've decided to try something else but I'm not getting it to work correctly.</p>

<p>Any suggestions?</p>

<pre><code>echo '&lt;script language="javascript"&gt;';


for ($size = 0; $size &lt; sizeof($teamsarray);$size++){

    echo "var teamsarray[".$size."] = ".$teamsarray[$size].";\n";


    }

echo 'function addrow(innerid, size){


for (var i = 0;i&lt; size; i++ ){

html = html + "&lt;option value = " + teamsarray[i] + "&gt;"+teamsarray[i]+"&lt;/option&gt;";


    }

html = html +"&lt;/select&gt;";
}&lt;/script&gt;';
</code></pre>

<p>basically what I'm trying to do is echo the javascript through php.  I'm trying to make a dropdown with values that I get from php.  Which will be added dynamically with the addrow function.</p>
