Re: problem - myDiv.style.display='none' doesn't make anything invisible.



Jake Barnes wrote :
Imagine I've this block of HTML:


Providing an url where a webpage can be examined, tested (markup validation, http headers, mime type supported, CSS validation, etc.) conveniently with tools, verified is a lot more convenient for all parties involved. Here, we don't see all of possible code and we have to "imagine" or create a page ourselves.


<p>Alex Schein Mailing List <input type="checkbox"
name="newslettersToUse[]" value="133156"> (<a href="mcControlPanel.php"
onClick="hideOrShowDivById('emailList133156'); return false;">See
emails?</a>

If javascript support is disabled or inexistent, will your code still work? If not, then you should make it a button and not a link. Even if javascript support is active, enabled, semantically speaking, I think you should be using a button, not a link since the button will toggle the display of a form.

)</p>
<form method="post" action="mcControlPanel.php"
id="emailList133156" style="display:none;"><textarea
name="formInputs[cbModifier19]">nazjeehaj@xxxxxxx,
birjdmajn9989@xxxxxxxxxxx, mjjjengersg@xxxxxxxxx,
jj1223@xxxxxxxxx</textarea>
<input type="submit" value="Edit List">
<input type="hidden" name="choiceMade"
value="standardUpdate">

<input type="hidden" name="formInputs[cbId]"
value="133156">
</form>



and imagine I've this javascript function:



function hideOrShowDivById(optionDivId) {
if (document.getElementById(optionDivId)) {

If the id of the element passed is a form element, then it's easier to follow your code and imagine what is happening by naming that parameter something like FormId or strFormId, not optionDivId.

var optionDiv = document.getElementById(optionDivId);
if (optionDiv.style.display == 'block') {
optionDiv.style.display='none';
} else {
optionDiv.style.height='auto';

This is unneeded. The default height value of a form is auto. Unless, of course, it was modified by code we don't see here.

optionDiv.style.display='block';
optionDiv.style.visibility='visible';

Default value of CSS property visibility is visible. So, that instruction is unneeded, unless, again, we don't see all the code and visibility was changed somewhere else.

}
} else {
alert("There was no item on the page called " + optionDivId);
}
}



Why would I keep getting the alert "There was no item on the page"?


I don't know. One thing is clear: it means your script fails at the external if..else:
if (document.getElementById(optionDivId)) fails.

The HTML block above is the first item in a list of 8. For some reason,
it is visible, despite display being set to "none". The other 7 items
are invisibile, as you'd expect. And the above Javascript function
works fine on the other 7 items.

What am I missing?

You are missing an url to allow us to examine the whole page for sure. You *_first_* have to make sure your markup code validates when trying to debug those problems.
In strict DTD, you will need to wrap the textarea within a block-level element, like a <p> or a <div>.

Gérard
--
remove blah to email me
.



Relevant Pages

  • Fastcode Status
    ... the Delphi version problem etc. ... We decided to support D5 based on a voting. ... not consider the huge impact D5 support would have on validation. ... when we placed D6 to D2005 in the targets and decided to benchmark ...
    (borland.public.delphi.language.basm)
  • RE: XML Validation problem
    ... the errors for each validation in each webmethod call, ... Microsoft MSDN Online Support Lead ... nature are best handled working with a dedicated Microsoft Support Engineer ... I have a web servicce which receives an XMLDocument and then uses the ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Summary of (dis)agreements on latewst FastCode developments
    ... > I would like to see all subbench results in main report as normal. ... Please respect all the Fastcode rules and conventions. ... Making an effort to support Delphi 5 is not the same thing as officially supporting ... >> Validation is aborted after 256 failures, ...
    (borland.public.delphi.language.basm)
  • RE: RegularExpressionValidator bug on firefox
    ... should have coded the validation rule differently for enter key and mouse ... selection cases. ... Microsoft MSDN Online Support Lead ... strangely enough when I select that saved form value using the ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: RegularExpressionValidator bug on firefox
    ... should have coded the validation rule differently for enter key and mouse ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ... strangely enough when I select that saved form value using the ...
    (microsoft.public.dotnet.framework.aspnet)