[thelist] style.display = 'none' and form elements
Ben Gustafson
Ben_Gustafson at lionbridge.com
Tue Oct 7 12:05:42 CDT 2003
I'm trying to set up a form validation routine where certain form elements
are removed from the page given user input. The way I am hiding the elements
is by using the style.display property. My understanding of display is that
display = 'none' should take the element out of the document flow and
elements array entirely, as if it were not there at all. But a simple test
seems to show that this is not the case:
<html>
<head>
<script language="JavaScript1.2"><!--
var elems = document.getElementsByTagName("input");
function hide()
{
for (var i=0; i<elems.length; i++)
if (elems[i].name == "inText")
elems[i].style.display = 'none';
}
function checkIfHidden()
{
for (var i=0; i<elems.length; i++)
alert(elems[i].name + ": " +
elems[i].style.display);
return true;
}
//--></script>
</head>
<body>
<input type="button" name="hide" value="Hide" onClick="hide();">
<form action="test.asp" name="test" id="test" method="get"
onSubmit="checkIfHidden();">
<input type="text" name="inText">
<input type="submit" name="btn">
</form>
</body>
</html>
The inText element is still found in the checkIfHidden() loop, and it still
gets put in the query string when the form is submitted. I have tested this
in IE6 and NS7.1 Am I misunderstanding how display is used or what it does?
Thanks,
--Ben
More information about the thelist
mailing list