PDA

View Full Version : Inserting Forms tags into Div - Runtime Exception Error



maheshexp
09-28-2007, 02:25 PM
When I try inserting a "<form>" tag inside the "div" tag. I get "Unknown runtime exception error.

<div id="a"></div>

document.getElementById("a").innerHTML = "<form id='x'> </form>";

coothead
09-28-2007, 03:26 PM
Hi there maheshexp,

it works without error for me. ;)

You might like to try using the DOM instead...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
window.onload=function() {
frm=document.createElement('form');
frm.setAttribute('id','x');

inp=document.createElement('input');
inp.setAttribute('value','maheshexp');
frm.appendChild(inp);

document.getElementById("a").appendChild(frm);

alert('form id="'+document.forms[0].id+'"');
alert('type="'+document.forms[0][0].type+'"');
alert('value="'+document.forms[0][0].value+'"')
}
</script>

</head>
<body>

<div id="a"></div>

</body>
</html>
coothead