Topic: This belongs in the DOM form, but the door was locked. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26710" title="Pages that link to Topic: This belongs in the DOM form, but the door was locked. (Page 1 of 1)" rel="nofollow" >Topic: This belongs in the DOM form, but the door was locked. <span class="small">(Page 1 of 1)</span>\

 
Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole i
Insane since: Mar 2002

posted posted 09-23-2005 23:05

Is there anyway to add an event handler in IE and Mozilla/Firefox
dynamiclly and also pass it a varable?

code:
<html>
	<head>
		<title>Adding Properties Dynamicly</title>
		<!-- Import the classes -->
		<script type="text/javascript" src="./js4/Employee.js"></script>
		<script type="text/javascript">
			function pageInit()
			{
				
				
				var textBox = document.getElementById("textbox");
				
				var onFocusAttr = document.createAttribute("onfocus");
				
				onFocusAttr.nodeValue = "callMeOnFocus(textbox)";
				
				textBox.setAttributeNode(onFocusAttr);
				
				
				alert(textBox.getAttribute("onfocus"));
			}
			
			function callMeOnFocus(textBox)
			{
				alert("callMeOnFocus in function");
				var changeText = document.getElementById("changeOnFocus");
				
				changeText.innerHTML = textBox.value;
			}
		</script>
	</head>
	<body onload="pageInit();">
		<div id="changeOnFocus">text</div>
		<input type="text" id="textbox" onclick="alert(textBox.value)"/>
	</body>
</html>



thanks,



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 09-24-2005 03:32

*whistles casually and boots it over to the DOM forum after unlocking the door*

There's an article on A List APart about this, custom scripted DOM triggers. I believe there's variable passing involved too. When I find it (or if anyone finds it first, feel free) I'll let you know.


Justice 4 Pat Richard

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-24-2005 03:41

sure.

textBox = document.getElementById("textbox");
textBox.onfocus = callMeOnFocus;

It's actually even easier than that in this case

you could do this

code:
<html>
	<head>
		<title>Adding Properties Dynamicly</title>
		<!-- Import the classes -->
		<script type="text/javascript">
			function pageInit()
			{
				
				
				var textBox = document.getElementById("textbox");
				textBox.onfocus = function () {
					var changeText = document.getElementById("changeOnFocus");
					changeText.innerHTML = this.value;
				}
			}
		</script>
	</head>
	<body onload="pageInit();">
		<div id="changeOnFocus">text</div>
		<input type="text" id="textbox"/>
	</body>
</html>



In this. because you are trying to get the value of the element that you're making the focus handler for, the "this" statement refers to itself




.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 09-24-2005 03:53)

Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole i
Insane since: Mar 2002

posted posted 09-26-2005 19:11

Hey thanks alot! That a list apart article really did the trick! It's all about the custom attributes...

*Maskkkk runs off to write a new DTD*



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu