Re: problem - myDiv.style.display='none' doesn't make anything invisible.
- From: Gérard Talbot <newsblahgroup@xxxxxxxxxxx>
- Date: Sat, 11 Mar 2006 00:07:36 -0500
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
.
- References:
- problem - myDiv.style.display='none' doesn't make anything invisible.
- From: Jake Barnes
- problem - myDiv.style.display='none' doesn't make anything invisible.
- Prev by Date: problem - myDiv.style.display='none' doesn't make anything invisible.
- Next by Date: Re: Method for Dynamically populating tables
- Previous by thread: problem - myDiv.style.display='none' doesn't make anything invisible.
- Next by thread: Re: problem - myDiv.style.display='none' doesn't make anything invisible.
- Index(es):
Relevant Pages
|