P
Phil Powell
Consider this code:
<code>
<pre>
<html>
<head>
<script type="text/javascript" language="JavaScript">
<!--
function verifyForm(docForm) {
var errMsg = "";
errMsg = verifyFormElements(docForm);
if (errMsg != "") {
alert(errMsg);
return false;
}
return true;
}
function verifyFormElements(docForm) {
var errMsg = "";
var canUseElementById = (docForm.getElementById);
if (canUseElementById && docForm.getElementById("lastname").value ==
"") {
errMsg += "Please enter your last name\\n\\n";
}
if (canUseElementById && docForm.getElementById("firstname").value ==
"") {
errMsg += "Please enter your first name\\n\\n";
}
var dropdown = docForm.getElementById("category");
if (canUseElementById && dropdown.options
[dropdown.selectedIndex].value == "") {
errMsg += "Please choose a catgory\\n\\n";
}
return errMsg;
}
//-->
</script>
</head>
<body>
<form method="post" action="here" onsubmit="return verifyForm(this)">
<table border="0">
<tr>
<td>Last name:</td>
<td><input id="lastname" name="lastname" size="30"></td>
</tr>
<tr>
<td>First name:</td>
<td><input id="firstname" name="firstname" size="30"></td>
</tr>
<td>Category:</td>
<td>
<select id="category" name="category">
<option value="1">Security</option>
<option value="2">IT</option>
<option value="3">Administration</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="submit"></
td>
</tr>
</table>
</form>
</body>
</html>
</pre>
</code>
When I try to run it in IE6 (only option allowed by me at this time -
honestly, I am not allowed to install any other browser yet here at
work!) I get the "Object does not allow this property or method" error
on the following line:
var dropdown = docForm.getElementById("category");
Why does this happen? Is this an IE6 hiccup on using ID elements on a
dropdown in Javascript or am I missing something else?
Thanks
<code>
<pre>
<html>
<head>
<script type="text/javascript" language="JavaScript">
<!--
function verifyForm(docForm) {
var errMsg = "";
errMsg = verifyFormElements(docForm);
if (errMsg != "") {
alert(errMsg);
return false;
}
return true;
}
function verifyFormElements(docForm) {
var errMsg = "";
var canUseElementById = (docForm.getElementById);
if (canUseElementById && docForm.getElementById("lastname").value ==
"") {
errMsg += "Please enter your last name\\n\\n";
}
if (canUseElementById && docForm.getElementById("firstname").value ==
"") {
errMsg += "Please enter your first name\\n\\n";
}
var dropdown = docForm.getElementById("category");
if (canUseElementById && dropdown.options
[dropdown.selectedIndex].value == "") {
errMsg += "Please choose a catgory\\n\\n";
}
return errMsg;
}
//-->
</script>
</head>
<body>
<form method="post" action="here" onsubmit="return verifyForm(this)">
<table border="0">
<tr>
<td>Last name:</td>
<td><input id="lastname" name="lastname" size="30"></td>
</tr>
<tr>
<td>First name:</td>
<td><input id="firstname" name="firstname" size="30"></td>
</tr>
<td>Category:</td>
<td>
<select id="category" name="category">
<option value="1">Security</option>
<option value="2">IT</option>
<option value="3">Administration</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="submit"></
td>
</tr>
</table>
</form>
</body>
</html>
</pre>
</code>
When I try to run it in IE6 (only option allowed by me at this time -
honestly, I am not allowed to install any other browser yet here at
work!) I get the "Object does not allow this property or method" error
on the following line:
var dropdown = docForm.getElementById("category");
Why does this happen? Is this an IE6 hiccup on using ID elements on a
dropdown in Javascript or am I missing something else?
Thanks