Discussion:
show/hide used on checkboxes not working on IE6
(too old to reply)
sergio
2004-08-12 14:31:19 UTC
Permalink
Hi all,
I have created the following script that will show/hide a menu based on
checkboxes. It works fine in Opera but not on IE6!
Does anybody knows a workaround this problem?
Thanks for your response.
Sergio


------------------------------------------------
<script language="JavaScript" type="text/javascript">
function dodisplaytbyarray(thewhat) {
if (navigator.appName.indexOf("Microsoft",0) != -1) {
var docloc = "document.all.",style = ".style";
}
var thearrays = new Array();

thearrays = thewhat.split("|");
for (var i = 0; i < "+thearrays+".length; i++) {
eval(docloc+thearrays[i]+style+".visibility='visible'");
eval(docloc+thearrays[i]+style+".position='relative'");
}
</script>
<form action="" method="post">
<div class="form-item"><div id="cat73|cat88"><input type="checkbox"
class="form-checkbox" name="edit[Category][73]" value="73"
onchange="dodisplaytbyarray('cat1')" > business</div>
<div style="visibility:hidden;position:absolute;top:0;left:0"
id="cat1"><input type="checkbox" class="form-checkbox"
name="edit[Category][1]" value="1">-- agriculture</div>
<div style="visibility:hidden;position:absolute;top:0;left:0"
id="cat88"><input type="checkbox" class="form-checkbox"
name="edit[Category][88]" value="88">-- B2B</div>
</form>
Michael Winter
2004-08-12 20:06:31 UTC
Permalink
On Thu, 12 Aug 2004 16:31:19 +0200, sergio <***@nospam.com> wrote:

[snip]
Post by sergio
<script language="JavaScript" type="text/javascript">
The language attribute is deprecated; remove it. Moreover, the type
attribute makes it redundant.
Post by sergio
function dodisplaytbyarray(thewhat) {
if (navigator.appName.indexOf("Microsoft",0) != -1) {
var docloc = "document.all.",style = ".style";
}
var thearrays = new Array();
thearrays = thewhat.split("|");
for (var i = 0; i < "+thearrays+".length; i++) {
eval(docloc+thearrays[i]+style+".visibility='visible'");
eval(docloc+thearrays[i]+style+".position='relative'");
}
I can guarantee, even without testing it, that that script won't work in
any browser. Even if you corrected the syntax errors, it only has a chance
of working in IE, and I don't see it doing anything useful even then.

If you retyped this, I suggest you don't. It usually leads to errors.
Repost the script and HTML, or better yet, a URL to the page.
Post by sergio
</script>
<form action="" method="post">
<div class="form-item"><div id="cat73|cat88"><input type="checkbox"
I also suggest that you validate your HTML. The id in that second DIV
element is invalid. id attributes may only contain "letters, digits
([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods
(".")" (HTML 4.01 Specification). They must also "begin with a letter
([A-Za-z])".

[snip]

Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
sergio
2004-08-13 08:09:04 UTC
Permalink
Michael,
The script is meant to work on all browsers, but the example posted is for
the group to help me have it work on IE.
Post by Michael Winter
I can guarantee, even without testing it, that that script won't work in
any browser. Even if you corrected the syntax errors, it only has a chance
of working in IE, and I don't see it doing anything useful even then.
I took the following lines out, to simplify the isolation of the bug, it
made no sense to post part of the script that IS working:
else (navigator.appName.indexOf("Netscape",0) != -1) {
var docloc = "document.",style="";
}

Now my script: can you please DO test it in IE? If you have suggestions on
the main problem, please feel free to contribute.
Post by Michael Winter
If you retyped this, I suggest you don't. It usually leads to errors.
Repost the script and HTML, or better yet, a URL to the page.
I am sorry I don't understand, what usually leads to errors?
What I have posted is an isolation of a bug in IE, once fix it should work
(only in IE) as the rest of my script (useless to post) DOES work in NN and
Opera.
Post by Michael Winter
I also suggest that you validate your HTML. The id in that second DIV
element is invalid. id attributes may only contain "letters, digits
Indeed you are right. This is a typo from me when posted the example it
should indeed read
<div id="cat88">

Now, I am sorry to say this but HTML valid or not valid, the script is not
working in IE. I attach a valid HTML so you can please TEST it and
contribute on the javascript.
Thanks,
Sergio
---------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title>Tidy example</title></head><body>
<script type="text/javascript">
function dodisplaytbyarray(thewhat) {
if (navigator.appName.indexOf("Microsoft",0) != -1) {
var docloc = "document.all.",style = ".style";
}
var thearrays = new Array();

thearrays = thewhat.split("|");
for (var i = 0; i < "+thearrays+".length; i++) {
eval(docloc+thearrays[i]+style+".visibility='visible'");
eval(docloc+thearrays[i]+style+".position='relative'");
}
</script>
<form action="" method="post">
<div id="cat73"><input type="checkbox"
class="form-checkbox" name="edit[Category][73]" value="73"
onchange="dodisplaytbyarray('cat1')" > business</div>
<div style="visibility:hidden;position:absolute;top:0;left:0"
id="cat1"><input type="checkbox" class="form-checkbox"
name="edit[Category][1]" value="1">-- agriculture</div>
<div style="visibility:hidden;position:absolute;top:0;left:0"
id="cat88"><input type="checkbox" class="form-checkbox"
name="edit[Category][88]" value="88">-- B2B</div>
</form>
</body></html>

Robert
2004-08-12 20:19:22 UTC
Permalink
Post by sergio
Hi all,
I have created the following script that will show/hide a menu based on
checkboxes. It works fine in Opera but not on IE6!
Does anybody knows a workaround this problem?
Thanks for your response.
Sergio
I'll provide some more information to the problem here. Maybe it will
help someone come up with a solution...


I am not sure why IE is delaying displaying the data. If you open
someother window untop of the IE window and you take the other window
away, IE will show the change. Showhow, IE isn't noticing the change
to the screen. Sometimes minimize will do the trick and sometimes not.
Openning up someother window above the IE window where it covered the
change always showed the change. Obviously, you need to open the
second windo after doing the change. IE displays source worked for
me.

I have seen this before on the Mac version. I kind of ignored it
because of the small market share of the Mac version of IE. I tried
using focus(), but that didn't help. I tried this on MacOS 10.2.6
with IE 5.2.

I included a second file below. I start with item being visible.
Clicking on email will make one line invisible. Clicking on print
makes all three input fiels visible. This works in IE 5.2 on MacOS
10.2.6.

There may be some discussion of this in this forum.

Robert

---------------------- IE delays displaying. ---------

<html>
<head>
<title>forms checking</title>


<style type="text/css">
.form-checkbox {color:black; }
.form-item {color:black; }
</style>

<script type="text/javascript">
function dodisplaytbyarray(thewhat) {

var thearrays = new Array();

thearrays = thewhat.split("|");
// Do not have a clue what "+thearrays+" is about
// Changed it to thearrarys
for (var i = 0; i < thearrays.length; i++) {

// Check if the getElementById method is available
if (document.getElementById)
{
document.getElementById(thearrays[i]
).style.visibility = 'visible';

}
else if (document.all)
{
alert("Running an older version of IE.");
// I do not know the syntax to avoid the eval.
// I assume there is a way.
eval("document.all." + thearrays[i] +
".style.visibility = 'visible'");
}
else
{ alert("Cannot change visibility of address field"); }

} // of for
} // of function

</script>
</head>

<body>
<br><br><br><br>
<p>Please try out our form.</p>
<form action="" method="post">
<div class="form-item">
<div id="cat73|cat88">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][73]"
value="73"
onchange="dodisplaytbyarray('cat1')" > business
</div>
<div style="visibility:hidden;position:absolute;top:0;left:0"
id="cat1">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][1]"
value="1">-- agriculture
</div>
<div style="visibility:hidden;position:absolute;top:0;left:0"
id="cat88">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][88]"
value="88">-- B2B
</div>
</div>
</form>
</body>
</html>


--------------------------------------------------------------------
In a similar use of the hidden visible tag, IE works. Try this file:

<html>
<head>
<title>Radio buttons</title>

<style type="text/css">
.formStyle {position:relative; visibility:visible;}
</style>

<script type="text/javascript">

function validate()
{

var x = document.forms["myForm"];
var checkedButton;

// Figure out which radio button was pressed
if (x.receiveVia[0].checked == true)
{ checkedButton = x.receiveVia[0].value;}
else if (x.receiveVia[1].checked == true)
{ checkedButton = x.receiveVia[1].value;}
else
{ checkedButton = '';}

var varName = x.theName.value;
var varEmail = x.theEmail.value;
var varAddress = x.theAddress.value;

alert("checkedButton = " + checkedButton +
" varName = " + varName +
" varEmail = " + varEmail +
" varAddress = " + varAddress);

// I changed submitOK to a boolean variable.
var submitOK = true;

// Validate email: name and email

if (checkedButton == "byEmail")
{
alert("verifying email fields.");

if (varName == '')
{
alert("Please fill in your Name");
submitOK = false;
}
if (varEmail == '')
{
alert("Please fill in Email");
submitOK = false;
}
if (varAddress != '')
{
alert("Please erase the address field.");
submitOK = false;
}

return submitOK;

}

// Validate print: name, email, and address

else if (checkedButton=="printed")
{
alert("Verifying printed fields");
// Error message should be in the order on the form
if (varName.length == '')
{
alert("Please fill in your Name");
submitOK = false;
}
if (varEmail == '')
{
alert("Please fill in Email");
submitOK = false;
}
if (varAddress == '')
{
alert("You must enter your Address");
submitOK = false;
}

return submitOK;
}
else
{
alert("You need to select either email or print.");
return false;
}

}

function showHidden(doWhat)
{
// Check if the getElementById method is available
if (document.getElementById)
{
document.getElementById("field3").style.visibility = doWhat;
}
else if (document.all)
{
alert("Running an older version of IE.");
document.all.field3.style.visibility = doWhat;
}
else
{ alert("Cannot change visibility of address field"); }
}
</script>

</head>

<body>

<p>Please try out our form.</p>

<form name="myForm"
action="http://www.nonamedomain.com"
method="POST"
onsubmit="alert('submitting');return validate();">
<!-- semicolons (;) are recommended in event handlers like onclick -->
<p><input type="radio" name="receiveVia" value="printed"
onclick="showHidden('visible');">&nbsp;Printed
brochure</p>
<p><input type="radio" name="receiveVia" value="byEmail"
onclick="showHidden('hidden');
document.forms['myForm'].theAddress.value = '';">&nbsp;Via
Email</p>
<!-- I like to use component names to avoid conflicts with
reserved words. -->
<p>Name:<br>
<input type="text" name="theName" size="20"><br><br>
Email:<br>
<input type="text" name="theEmail" size="20"><br>
<script type="text/javascript">
// Only insert a div if we can change it
if (document.getElementById || document.all)
{ document.write("<div id='field3' class='formStyle'>");}
</script>
Postal address:<br>
<input type="text" name="theAddress" size="40">
<script type="text/javascript">
if (document.getElementById || document.all)
{ document.write("</div>");}
</script>
</p>
<!-- Netscape 4.x doesn't seem to support the onclick event
handler, so I moved the checking code to the form
onsubmit. Netscape doesn't support the alt tag. -->
<p><input type="image" src="submit.gif" border="0" value="Submit"
width="75" height="17"

ALT="Submit button"></p>

</form>

<script type="text/javascript">
// In the case of a reload, the radio button may already be clicked.
// This code needs to be after the form.
var x = document.forms["myForm"];
if (x.receiveVia[0].checked == true)
{ showHidden('visible');}
else if (x.receiveVia[1].checked == true)
{ showHidden('hidden');}
else
{ ;}

</script>
</body>
</html>
Thomas 'PointedEars' Lahn
2004-08-12 20:54:46 UTC
Permalink
Robert crossposted over 4(!) newsgroups in 3(!) main hierarchies,
^^^^^^
Please do not write attribution novels. The name of the
poster of the precursor is sufficient most of the time,
see <http://netmeister.org/news/learn2quote.html>.
Post by Robert
Post by sergio
I have created the following script that will show/hide a menu based on
checkboxes. It works fine in Opera but not on IE6!
Does anybody knows a workaround this problem?
Thanks for your response.
Sergio
^^^^^^
How should one address you anyway?
Post by Robert
I'll provide some more information to the problem here. Maybe it will
help someone come up with a solution...
[more hundreds of lines of source code lacking a minimal clue about the
language]
<http://jibbering.com/faq/#FAQ2_3>


F'up2 comp.lang.javascript

PointedEars
Loading...