[HTML] JS quotes

Actually, what I'm really trying to accomplish here is basically this:

onClick="document.getElementById('button2').innerHTML = '<img src=\'images/news.png\' alt=\'\' border=\'0\' onMouseOver=\'MM_swapImage(\"Image4\",\"\",\"images/contact1.png\",0)\' onMouseOut=\'MM_swapImgRestore()\' '

I can get it to show the button just fine, but I would really prefer to see that onMouseOver, which I'm not getting.:?:

Well thanks again
 
Or, to avoid this messiness:

Code:
<script lang="javascript">
function setimg(element)
{
document.getElementById(element).innerHTML = '<img src="images/news.png" alt="" border="0" onMouseOver="MM_swapImage(\'Image4\', \'\', \'images/contact1.png\', 0);" onMouseOut="MM_swapImgRestore();">';
}
</script>

<... onClick="setimg('button2');" ... >

I always use double quotes for HTML attributes, and single quotes for strings in PHP and JS.
 
Daevius, I see how your script works...but it won't work for some reason...hmm...
Pieman, \\\" did not work.

Heres what I used word for word:

<script lang="javascript">
function setimg(element)
{
document.getElementById(element).innerHTML = '<img src="images/news.png" alt="" name="Image2" id="Image2" width="220" height="33" border="0" onMouseOver="MM_swapImage('Image2','','images/news1.png',0)" onMouseOut="MM_swapImgRestore()">';
}
</script>

<a href="javascript:;" onClick="document.getElementById('contentCell').innerHTML = 'text here'; document.getElementById('button4').innerHTML = '<img src=\'images/contact1.png\' alt=\'\' border=\'0\';';" onClick="setimg('button2')"><div id="button4"><img src="images/contact.png" alt="" name="Image4" id="Image4" width="220" height="33" border="0" onMouseOver="MM_swapImage('Image4','','images/contact1.png',0)" onMouseOut="MM_swapImgRestore()"></div></a><br />

suggestions? :D
 
Sorry, should have elaborate a bit more.

What I meant, is that you replace the JS script you have in the onClick attribute of the <a> tag.

This would somehow look like:
<script lang="javascript">
function setimg(text, button)
{
document.getElementById('contentCell').innerHTML = text;
document.getElementById(button).innerHTML = '<img src="images/contact1.png" border="0">';
}
</script>

<a href="javascript:;" onClick="link_on_click('text here', 'button4');><div id="button4"><img src="http://forum.ragezone.com/images/contact.png" ...></div></a><br />

So no HTML in HTML-inline JS. You need to separate JS from HTML as much as you can.

PS: This example is not what you want, but it gives a good indication what you should do (I do not know which values are variables etc).
 
Back