A
Andrew Falanga
Hello again,
I'm having trouble understanding why the element types in the form I'm
using aren't defined in my function. Below is the code (it's a
nonsense page that I'm using just to get my understanding correct).
In the function displayFormElements(), the form.type property isn't
defined, but yet the form.length was because the for loop only goes
for 3 iterations. Is there something wrong with how I'm passing the
form to the function?
Thanks for any help,
Andy
<html>
<head>
<script type="text/javascript">
function foo() {
document.write("foo");
alert("foo");
}
function displayFormElements(form) {
document.write("displayFormElements called");
var length = form.length;
for(var i = 0; i < length; i++) {
document.write("element " + i + " is " + form.type + "<BR>");
}
}
function CheckForNull() {
alert("CheckForNull called");
var formId=document.getElementById("myForm");
if(formId.elements[0].value == "") {
alert("form may not be null");
return false;
}
return true;
}
</script>
</head>
<body>
Form test
<form id="myForm" onsubmit="return CheckForNull()" action="index.html"
method="post">
<input type=text name="text1"></input>
<textarea>example text</textarea>
<input type="submit" value="submit" />
</form>
<P>
<script language="javascript" type="text/javascript">
var theform = document.getElementById("myForm");
displayFormElements(theform);
document.write("<BR>");
for(var i = 0; i < theform.length; i++) {
document.write("element " + i + " is type: " + theform.elements
.type + "<BR>");
}
</script>
</body>
</html>
I'm having trouble understanding why the element types in the form I'm
using aren't defined in my function. Below is the code (it's a
nonsense page that I'm using just to get my understanding correct).
In the function displayFormElements(), the form.type property isn't
defined, but yet the form.length was because the for loop only goes
for 3 iterations. Is there something wrong with how I'm passing the
form to the function?
Thanks for any help,
Andy
<html>
<head>
<script type="text/javascript">
function foo() {
document.write("foo");
alert("foo");
}
function displayFormElements(form) {
document.write("displayFormElements called");
var length = form.length;
for(var i = 0; i < length; i++) {
document.write("element " + i + " is " + form.type + "<BR>");
}
}
function CheckForNull() {
alert("CheckForNull called");
var formId=document.getElementById("myForm");
if(formId.elements[0].value == "") {
alert("form may not be null");
return false;
}
return true;
}
</script>
</head>
<body>
Form test
<form id="myForm" onsubmit="return CheckForNull()" action="index.html"
method="post">
<input type=text name="text1"></input>
<textarea>example text</textarea>
<input type="submit" value="submit" />
</form>
<P>
<script language="javascript" type="text/javascript">
var theform = document.getElementById("myForm");
displayFormElements(theform);
document.write("<BR>");
for(var i = 0; i < theform.length; i++) {
document.write("element " + i + " is type: " + theform.elements
.type + "<BR>");
}
</script>
</body>
</html>