Forum Moderators: open
<html>
<head><title>flow and forms</title>
</head>
<body>
<form id="form1"><p>This is form1.</p></form>
<form id="form2"><p>This is form2.</p></form>
<form id="form3"><p>This is form3.</p></form>
<script type="text/javascript">
for(var form in document.forms){
document.getElementById('docById').innerHTML= document.forms[form];
}
</script>
<div id="docById"></div>
<div>
<script>
for(var idx=0; idx<=document.forms.length; idx++){
document.write("<br />"+document.forms[idx].id);
}
</script></div>
</body>
</html>
<html>
<head><title>flow and forms</title>
</head>
<body>
<form id="form1"><p>This is form1.</p></form>
<form id="form2"><p>This is form2.</p></form>
<form id="form3"><p>This is form3.</p></form>
<div id="docById"></div>
<script type="text/javascript">
var msg = "";
var idx = 0;
for(idx=0; idx<=document.forms.length; idx++){
msg += "<p>" + document.forms[idx].id + "<\/p>";
}
document.getElementById('docById').innerHTML= msg;
</script>
</body>
</html>
if (document.getElementById('my_id')) {alert(document.getElementById('my_id').value);}
<html>
<head><title>flow and forms</title>
</head>
<body>
<form id="form1"><p>This is form1.</p></form>
<form id="form2"><p>This is form2.</p></form>
<form id="form3"><p>This is form3.</p></form>
<script type="text/javascript">
var idx=0;
if(document.forms.length !==0){
for(var idx=0; idx<=document.forms.length; idx++){
document.write("Form: " + idx + " is " + document.forms[idx].id + "</p>");
}
}
</script>
</body>
</html>
innerHTML WAS a Microsoft proprietary method, but has been adopted by all the current browsers, and has been standardized and included in HTML5.
In example if you try to use JavaScript with (X)HTML that was loaded via AJAX and dumped on to the page via innerHTML you can't give focus and scripts might work.
<!DOCTYPE html>
<html>
<head>
<title>innerHTML test</title>
</head>
<body>
<div id="container"></div>
<script>
var container = document.getElementById('container');
container.innerHTML = "<div id='mydiv'><input id='foo'><\/input><input type='button' id='btn' value='click me'><\/input><\/div>";
var btn = document.getElementById('btn');
var foo = document.getElementById('foo');
btn.onclick = function () {
foo.focus();
foo.value = "This works just fine.";
}
</script>
</body>
</html>
In my mind I'm inclined to suspect innerHTML because it's too easy to use
I plan on using document.write for debugging