K
Ken
Hello,
I'm wondering if someone could tell me why the following code would
work as expected in Firefox but not IE7.
Basically, I am attempting to dynamically create a text box and have
javascript code attached to an event on that textbox. What should
happen is this:
- Click "Create Element".
- A new textbox appears.
- Hover your mouse over the textbox, and an alert is displayed stating
"You are pointing at a dynamically created control!"
On Firefox, this works. On IE7, the textbox appears but no alert
onmouseover occurs. Of course, the code works when I try it using
static HTML.
Any ideas? Is this a security limitation or perhaps I have to do this
another way for IE7?
Thanks in advance!
===========
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
<!--
function addTextBox( targetElementId )
{
var newElement = document.createElement('input');
newElement.setAttribute( 'type', 'text');
newElement.setAttribute( 'name', 'myTextfield');
newElement.setAttribute(
"onmouseover",
"javascript:alert('You are pointing at a dynamically created
control!'); "
);
var targetElement = document.getElementById( targetElementId );
targetElement.appendChild( newElement );
}
function clearTextBox( targetElementId )
{
var targetElement = document.getElementById( targetElementId );
targetElement.innerHTML = '';
}
//-->
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="" >
<label for="textfield"></label>
<input type="button" name="btnCreateElement"
value="Create Element"
onclick="addTextBox( 'placeHolder'); " />
<br />
<label for="label"></label>
<input type="button" name="btnClearElement"
value="Clear Element"
onclick="clearTextBox( 'placeHolder' );" />
<br />
<div id="placeHolder" />
</form>
</body>
</html>
I'm wondering if someone could tell me why the following code would
work as expected in Firefox but not IE7.
Basically, I am attempting to dynamically create a text box and have
javascript code attached to an event on that textbox. What should
happen is this:
- Click "Create Element".
- A new textbox appears.
- Hover your mouse over the textbox, and an alert is displayed stating
"You are pointing at a dynamically created control!"
On Firefox, this works. On IE7, the textbox appears but no alert
onmouseover occurs. Of course, the code works when I try it using
static HTML.
Any ideas? Is this a security limitation or perhaps I have to do this
another way for IE7?
Thanks in advance!
===========
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
<!--
function addTextBox( targetElementId )
{
var newElement = document.createElement('input');
newElement.setAttribute( 'type', 'text');
newElement.setAttribute( 'name', 'myTextfield');
newElement.setAttribute(
"onmouseover",
"javascript:alert('You are pointing at a dynamically created
control!'); "
);
var targetElement = document.getElementById( targetElementId );
targetElement.appendChild( newElement );
}
function clearTextBox( targetElementId )
{
var targetElement = document.getElementById( targetElementId );
targetElement.innerHTML = '';
}
//-->
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="" >
<label for="textfield"></label>
<input type="button" name="btnCreateElement"
value="Create Element"
onclick="addTextBox( 'placeHolder'); " />
<br />
<label for="label"></label>
<input type="button" name="btnClearElement"
value="Clear Element"
onclick="clearTextBox( 'placeHolder' );" />
<br />
<div id="placeHolder" />
</form>
</body>
</html>