Forum Moderators: open

Message Too Old, No Replies

onClick and onMouseup

         

hrudayamm

8:27 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Hi!

I need the below code work for onClick event. It simply dosent work, I could not figure out why,
Try to type in some thing in the iframe and click on the fontsize 20 to see what i mean.

please help :(

Lalith

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="JavaScript">
function Init()
{
document.getElementById("edit").contentWindow.document.designMode = 'On';
}
function setfont()
{
document.getElementById('edit').contentWindow.document.execCommand('fontsize', false, 6);
}
</script>
<body onLoad="Init()">
<table>
<tr><td onMouseDown="setfont();" style="cursor:pointer; text-decoration:underline;">FontSize 20</td><td>This work if I use onMouseDown or onMouseOver or onMOuseOut</td></tr>
<tr><td onClick="setfont();" style="cursor:pointer; text-decoration:underline;">FontSize 20</td><td>This dosent work if I use onClick or onMouseUp</td></tr>
</table>
<iframe id="edit" name="edit" style="width: 100%; height:370px; border:1px none #d9d9d9;"></iframe>
</body>
</html>

rocknbil

8:36 pm on Feb 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try using links?

<td><a href="#" onClick="setfont(); return false;" style="cursor:pointer;">FontSize 20</a></td>

hrudayamm

8:45 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



thanx a lot it worked :)
but can u tell me why it did not for the mouseup and onclick but it did for the other events?

Lalith

rocknbil

2:37 am on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure. I didn't want to say at the risk of looking stupid, which unfortunately is not a long walk for me. :-) But here goes hehe . . .

I suspect it's more that the TD elements are not responding to the events while hyperlinks are. Play around with the links, changing the onclick to onmousedown and onmouseup to see what happens. You'll rarely need those events, but just so you know.

qazwer

3:35 am on Feb 28, 2005 (gmt 0)

10+ Year Member



You could also use a button if you wish.

<td><input type="button" onClick="setfont(); return false;" value="Font Size 20"></td>