struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <andrew.david.h...@gridnode.com>
Subject RE: [OT] dom - createElement("textarea") cannot invoke javascript
Date Tue, 10 Jun 2003 06:45:22 GMT
Been playing with your problem a few minutes and think Ive found the
problem.

Firstly your syntax was wrong.

What you meant to say was:
td5.setAttribute("ondblclick","alert('hello');");
instead of
td5.setAttribute("ondblClick=alert('hello')");

BUT unfortunately this correction still doesnt make it work....
As far as I can figure out, once you are at the stage of playing with the
browsers in-memory dom (as opposed to the unparsed source for the dom) then
the onXXX attributes dont take script source, but rather they take a
reference to a function. Im guessing that in the process of parsing the
source, the browser will convert the script in the onXXX attributes into a
function and substitute a reference to the function in the dom.

ie:
function foo()
{
  alert('hello');
}

td5.setAttribute("ondblclick",foo);

or alternatively the simpler notation
td5.ondblclick = foo;

See the following example (which our email clients will no doubt mangle
badly!):
##########################

<html>
	<head>
		<script type="text.javascript">

			function foo()
			{
				alert('hello');
			}

			function doTest()
			{
				var td5 = document.createElement("textarea");
				td5.setAttribute("name","mytextarea");
				td5.setAttribute("cols","10");
				td5.setAttribute("rows","2");
				td5.setAttribute("wrap","PHYSICAL");
 				td5.setAttribute('ondblclick',foo);
 				document.getElementById('test').appendChild(td5);
			}
		</script>
	</head>
	<body id="test" onload="doTest()">
	</body>
</html>

##########################
-----Original Message-----
From: Vijay Pawar [mailto:vspawar@orgltd.com]
Sent: Tuesday, 10 June 2003 14:06
To: Struts Users Mailing List
Subject: [OT] dom - createElement("textarea") cannot invoke javascript


Hi All,

I would be obliged if someone helps me in this.

I am dynamically creating rows in my jsp by using the dom-tree functions

To create a text field i use :-

document.createElement("<input name='type"+indexVal+"' type='text'
size='3' maxlength='3' ondblClick='alert(this.value)'>");

The above code works fine and on double clicking, the the alert is invoked.

Now to create a text area using dom i use the following code :-

var td5 =       document.createElement("textarea");
		td5.setAttribute("name","mytextarea");
		td5.setAttribute("cols","10");
		td5.setAttribute("rows","2");
		td5.setAttribute("wrap","PHYSICAL");

Now i wish to add a javascript event to this text area and so i tried the
following
		td5.setAttribute("ondblClick=alert('hello')");

But this does not work. Can anyone please tell me how to add javascript
events to a text area that is generated like this.

Thanking in advance,
Vijay


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message