views:

460

answers:

2

hi, how to pass a php variable to dynamicaly generated div's onclick event?

here is my code

while($rowset = mysql_fetch_array($result))
    {
    $idTT1++; 
    $editTT='b'.$idTT1;
    $hidTextTT='t'.$idTT1; $hidSubIdTT='s'.$idTT1;
    echo "<tr><td>".$rowset[1]." ".$rowset[2]."</td><td> &nbsp; </td> 
    <td class='table_label'>
    <div id='".$idTT1."' onclick='editView($idTT1,$editTT)' >".$rowset[3]."</div>";

    echo "<div id='".$editTT."' style='display:none;'>            
        <input id='".$hidSubIdTT."' name='box1' type='hidden' value='".$row['dDegreeName']."'>
        <input id='".$hidTextTT."' name='box2' type='text' value=''  />
        <input type='submit' value='Update' name='submit' 
        onclick='updateSubject($hidSubIdTT,$hidTextTT)'/>
        <input type='button' value='Cancel' name='Cancel' onclick='setEditView($idTT1,$editTT)'/>
    </div></td></tr>";
    }

i want to pass 2 variables $idTT1 and $editTT. im getting the value of $editTT1 in javascript but i cant get value of $editTT value in editView() javascript function.

+1  A: 

You need to put it between quotes. Something like this should work:

"<input type='button' value='Cancel' name='Cancel' onclick='setEditView(\"$idTT1\",\"$editTT\")'/>"
marcgg
+1 because you were quicker. We seem to be having the same answer 20 seconds apart all the time today :)
Pekka
+1  A: 

That is probably because you are not quoting the IDs. Try

setEditView(\"$idTT1\",\"$editTT\")

in the line before last.

Pekka
Aha, yeah, there are days like that ^^
marcgg