Results 1 to 4 of 4

Thread: what is wrong with my onmouseover?

  1. #1
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry what is wrong with my onmouseover?

    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>

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <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:
    Code:
    <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>
    - Mike

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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>';
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Mike & John,

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •