473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

show/hide used on checkboxes not working on IE6

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;l eft: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;l eft:0"
id="cat88"><input type="checkbox" class="form-checkbox"
name="edit[Category][88]" value="88">-- B2B</div>
</form>
Jul 23 '05 #1
9 2726
On Thu, 12 Aug 2004 16:31:19 +0200, sergio <no****@nospam.com> wrote:

[snip]
<script language="JavaScript" type="text/javascript">
The language attribute is deprecated; remove it. Moreover, the type
attribute makes it redundant.
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.
</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
Jul 23 '05 #2
"sergio" <no****@nospam.com> wrote in message news:<41*********************@news.skynet.be>...
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;l eft: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;l eft: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>
Jul 23 '05 #3
Robert crossposted over 4(!) newsgroups in 3(!) main hierarchies,
^^^^^^
while the subject being off-topic in 2 of them, without Followup-To:
"sergio" <no****@nospam.com> wrote in message
news:<41*********************@news.skynet.be>...
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>.
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?
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
Jul 23 '05 #4
"sergio" <no****@nospam.com> wrote in message news:<41*********************@news.skynet.be>...
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?


I have looked into the problem some more. It has to do with the event
handler. I changed it to onclick and IE seems to work better. IE
works fine with the onclick event handler and the inclusion of an
alert. Take out the alter and IE seems to miss some of the clicks.

I tried this in IE 5.2 on MacOS 10.2.6.

One should blame the OP if I posted the prior post too much because I
posted where the original post went too. Blame google.

I said the one script worked and the other did not. I didn't know why
at the time.

I tried the following routine:

<html>
<head>
<title>forms checking</title>
<style type="text/css">
..form-checkbox {color:black; }
..form-item {color:black; }
..formStyle {position:relative; visibility:visible;}
</style>

<script type="text/javascript">
function dodisplaytbyarray(thewhat) {
var x = document.forms["myForm"];
var checkedButton;
var thearrays = new Array();

if (x.elements["edit[Category][73]"].checked == true)
{ checkedButton = "visible";}
else
{ checkedButton = "hidden";}

alert("checkedButton = " + checkedButton);

thearrays = thewhat.split("|");

for (var i = 0; i < thearrays.length; i++) {

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

}
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 = " + checkedButton);
}
else
{ alert("Cannot change visibility of address field"); }

} // of for
} // of function

</script>
</head>

<body>
<br><br><br><br>
<!-- edit[Category][73] old name -->
<p>Please try out our form.</p>
<form action=""
method="post"
name="myForm">
<div class="form-item">
<div id="cat73|cat88">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][73]"
value="73"
onclick="dodisplaytbyarray('cat1')" > business
</div>
<div style="visibility:hidden;position:absolute;top:0;l eft: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;l eft:0"
id="cat88">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][88]"
value="88">-- B2B
</div>
</div>
</form>

</body>
</html>
Jul 23 '05 #5
Robert,
Thanks a lot for your help! I finally got it working. After some testing my
conclusion is that the <div style=position:??><input></input><div> does not
work very well when setting the position:absolute dynamically. That is why
your last post works well on showing, but it does not work well when
positioning.

So.... my workaround has been to use the attibute "display" which is part of
CSS1, seems to work on NN4 and IE4.

Below is the code.
Thanks again for your help,
Sergio

----------------------------------
<html>
<head>
<title>forms checking</title>
<script type="text/javascript">
function dodisplaytbyarray(thewhat) {
var x = document.forms["myForm"];
var thedisplay,ok;
var thearrays = new Array();

if (x.elements["edit[Category][73]"].checked == true)
{ thedisplay = "";}
else
{ thedisplay = "none";}
thearrays = thewhat.split("|");

for (var i = 0; i < thearrays.length; i++) {

// Check if the getElementById method is available
if (document.getElementById)
{
document.getElementById(thearrays[i]).style.display = thedisplay;
}
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.display = " + thedisplay);
}
else
{ alert("Cannot change visibility of address field"); }

}
}

</script>
</head>

<body>
<p>Please try out our form.</p>
<form action=""
method="post"
name="myForm">
<div id="cat73" class="form-item">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][73]"
value="73"
onclick="dodisplaytbyarray('cat1|cat88')"
business

</div>
<div style="display:none"
id="cat1">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][1]"
value="1">-- agriculture
</div>
<div style="display:none"
id="cat88">
<input type="checkbox"
class="form-checkbox"
name="edit[Category][88]"
value="88">-- B2B
</div>
text to see if it flows
</form>
</body>
</html>
Jul 23 '05 #6
On Fri, 13 Aug 2004 11:04:44 +0200, sergio <no****@nospam.com> wrote:

[snip]
// I do not know the syntax to avoid the eval.
// I assume there is a way.
eval("document.all." + thearrays[i] +
".style.display = " + thedisplay);


document.all[thearrays[i]].style.display = thedisplay;

By the way, just as you check for support of getElementById() and all[],
you should check that the style object is supported, too.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #7
sergio wrote:
[snip]

So.... my workaround has been to use the attibute "display" which is part of
CSS1, seems to work on NN4 and IE4.


Not in NN4.....
Mick
Jul 23 '05 #8
> So.... my workaround has been to use the attibute "display" which is part of
CSS1, seems to work on NN4 and IE4.


On IE 5.2 on MacOS 10.2.6, if you pause between clicks all is well.
If you click quickly, IE will eventually get confused. In IE 4.72 on
Windows 95, all is well.

NN4.x cannot reflow text.

Glad that I was able to assist.

Robert
Jul 23 '05 #9
JRS: In article <12****************@PointedEars.de>, dated Thu, 12 Aug
2004 22:54:46, seen in news:comp.lang.javascript, Thomas 'PointedEars'
Lahn <Po*********@web.de> posted :
Robert crossposted over 4(!) newsgroups in 3(!) main hierarchies,
^^^^^^
That is perfectly permissible, provided that he considers the article to
be on-topic in all, as the OP did. There is, rightly, nothing in the
current usenet standards against cross-hierarchy posting.

However, posting by the OP to c.l.j.j was unwise, since the group has no
legitimate existence. Why did you fail to note that?

Also, posts in borland.* should be injected at Borland's server only,
and not cross-posted; it is a private hierarchy, improperly copied on
some other servers. Why did you fail to note that? Why, indeed, did
you break that rule yourself?
while the subject being off-topic in 2 of them, without Followup-To:


There is no requirement to set follow-up to a single group, or to fewer
groups, if an author considers all groups to be on-topic. An author is
perfectly entitled to be wrong in such matters, provided that it is
unintentional.

"sergio" <no****@nospam.com> wrote in message
news:<41*********************@news.skynet.be>...


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>.


There is no such requirement in current thinking; see
http://www.ietf.org/internet-drafts/...-useage-00.txt
http://www.ietf.org/internet-drafts/...article-13.txt
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve | last post by:
Visual Studio 2003 C# Windows: I have a tree view control as my main menu control down the left side of my application. This has 2 Parent Nodes on it (Jobs and Employees). beneath these 2 main...
2
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
4
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
1
by: jbreaker | last post by:
Hi - I have a table with about 30 rows, which contain a checkbox and a bit of text each. What I'm trying to find a way to do is to have 2 buttons at the bottom of the page - HIDE & SHOW. When the...
4
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Is it possible to Hide/Show controls during a callback? I have a radio button list that does the callback. When it does the callback I need to refresh the grid to reflect the selected value...
1
by: femtox77 | last post by:
Hi, I try to show or hide a button when I click on checkboxes. I explain better. I'm learnig to use Jquery framework. I have a page with many rows and every row has a checkbox. I wanna show a...
1
by: sdanda | last post by:
I am working on vb.net.I am new to this..In my application i created four forms.Those are First.vb,f1.vb,f2.vb,f3.vb In First.vb I created 3 checkboxes and one button "Display".The checkboxes are...
13
by: rupak | last post by:
Hi! I have a multiple selection of checkboxes <input type='checkbox' name='coffee' id='col1' value='Address'/> <input type='checkbox' name='coffee' id='col2' value='Name'/> <input...
1
by: filch | last post by:
Hi, I am new to this forum ... so hello to all! I am trying to get a script working which will show or hide a table based on a user checking or unchecking a parent checkbox. This is the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.