Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding onclick function on a dynamically added table row
    primarykey
    data
    text
    <p>I have a page which displays records in a table and I am able to do that but after adding a code so a highlighted table row will change color, I am now getting error instead.</p> <pre><code>$result = mysqli_query($con,"SELECT * FROM mydb WHERE `Main Type`='main1' AND `DB Type`='Active' ORDER BY `Record ID`"); echo "&lt;table border='1' style='width:100%; font-family:arial,Serif;font-style:regular;font-size:12px; color:black' CELLPADDING='1' CELLSPACING='0'&gt; &lt;tr&gt; &lt;th&gt;Record ID&lt;/th&gt; &lt;th&gt;Address&lt;/th&gt; &lt;th&gt;City&lt;/th&gt; &lt;th&gt;State&lt;/th&gt; &lt;th&gt;Zip Code&lt;/th&gt; &lt;th&gt;County&lt;/th&gt; &lt;th&gt;Price&lt;/th&gt; &lt;th&gt;Bed&lt;/th&gt; &lt;th&gt;Bath&lt;/th&gt; &lt;th&gt;Square Foot&lt;/th&gt; &lt;th&gt;Year Built&lt;/th&gt; &lt;th&gt;As Is Value&lt;/th&gt; &lt;th&gt;DB Type&lt;/th&gt; &lt;th&gt;Main Type&lt;/th&gt; &lt;/tr&gt;"; while($row = mysqli_fetch_array($result)) { echo "&lt;tr onclick='toggle(this)'&gt;"; echo "&lt;td&gt;" . $row['Record ID'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Address'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['City'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['State'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Zip Code'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['County'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Price'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Bed'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Bath'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Square Foot'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Year Built'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['As Is Value'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['DB Type'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['Main Type'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;&lt;br&gt;"; echo "&lt;script type='text/javascript'&gt;"; echo "function toggle(it) { if ((it.style.backgroundColor == 'none') || (it.style.backgroundColor == '')){it.style.backgroundColor = 'yellow';}}"; echo "&lt;/script&gt;" mysqli_close($con); </code></pre> <p>Basically my main goal is if the user clicks on a row, the entire row will change color to indicate it is being selected. My more advance goal is a mousemove instead of onclick. I'm looking for the easiest and less complicated way to do this, I have this feeling that the solution is simple. I hope you guys can help.</p> <p>The error I'm getting is</p> <p>Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u560877965/public_html/hud.php on line 59</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload