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.
Any ideas?
Javascript
function addrow(innerid, teams){
alert(teams[1]);}
Here is how I pass it, this is all inside of an echo
<input type = "button" id = '.$buttonid.' value = "Agregar" onclick = "addrow(\'' . $leaguesarray[$numofleagues] . '\','.$teamsarray.')
So I call addrow(with a league value, and I also pass the array teamsarray from php
I've decided to try something else but I'm not getting it to work correctly.
Any suggestions?
echo '<script language="javascript">';
for ($size = 0; $size < sizeof($teamsarray);$size++){
echo "var teamsarray[".$size."] = ".$teamsarray[$size].";\n";
}
echo 'function addrow(innerid, size){
for (var i = 0;i< size; i++ ){
html = html + "<option value = " + teamsarray[i] + ">"+teamsarray[i]+"</option>";
}
html = html +"</select>";
}</script>';
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.