PDA

View Full Version : what is wrong with my onmouseover?



tvfoto
01-08-2007, 11:01 PM
Hello,

I want to mouseover on one table cell (<td>) and change the value of the header cell. I have no problem testing it this way:

<table border="1">
<tr>
<th id="hdr" width="50px"></th>
<td onmouseover="document.getElementById('hdr').innerHTML = '<p>heh</p>'";onmouseout="document.getElementById('hdr').innerHTML = ''";>mouseoverhere
</td>
</tr>
</table>

but when I try to apply the concept to the following, i have script error. I've tried number of ways to deal with single and double quotes and failed. Can you tell me what I did wrong? Thanks

<script>
......

doc = doc+"<td onmouseover='document.getElementById('hdr').innerHTML = '<p>heh</p>' " + " rowspan="+ height + " style='color:white;background:" + bkgcolor + "'"+">"+ "text here" +"</td>"

.....
</script>

mburt
01-08-2007, 11:21 PM
<table border="1">
<tr>
<th id="hdr" width="50px"></th>
<td onmouseover="document.getElementById('hdr').innerHTML = '<p>heh</p>'";onmouseout="document.getElementById('hdr').innerHTML = ''";>mouseoverhere
</td>
</tr>
</table>

The above semicolons in red are invalid and cause an error. It should be:

<table border="1">
<tr>
<th id="hdr" width="50px"></th>
<td onmouseover="document.getElementById('hdr').innerHTML = '<p>heh</p>'" onmouseout="document.getElementById('hdr').innerHTML = ''">mouseoverhere
</td>
</tr>
</table>

jscheuer1
01-08-2007, 11:31 PM
The main thing to remember is that whatever type of quotes are being used to delimit the string must be escaped if they appear in the string as literals. Also, it makes no sense to break the string if variable data isn't being inserted into it. It is difficult to be sure what result you are after but, this shouldn't give an error and looks like it is the result you are going for:


doc = doc+'<td onmouseover="document.getElementById(\'hdr\').innerHTML = \'<p>heh</p>\';" onmouseout="document.getElementById(\'hdr\').innerHTML = \'\';" rowspan="' + height + '" style="color:white;background-color:' + bkgcolor + ';">text here</td>';

tvfoto
01-09-2007, 02:35 PM
Mike & John,

Thanks guys. That's what I was looking for. Few more eyes are way better than one old one.