473,698 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/Hide form field in IE & Firefox

Hi y'all,
I found the toggle function (shown below) and applied it to a form of mine.
It works fine in IE, but in Firefox it appears to fail on the eval lines.

I've searched around but I can't seem to find the correct invocation to get
the field to appear in Firefox.

I've copied below the call and the html of the field itself.

Can anyone point me to what is wrong with it and more to the point, how to
get it working?

TIA
Regards
Paul

toggleT('divt1' ,'s');

function toggleT(_w,_h) {
if (document.all) { // is IE
if (_h=='s') eval("document. all."+_w+".styl e.visibility='v isible';");
if (_h=='h') eval("document. all."+_w+".styl e.visibility='h idden';");
} else { // is NS?
if (_h=='s') eval("document. layers['"+_w+"'].visibility='sh ow';");
if (_h=='h') eval("document. layers['"+_w+"'].visibility='hi de';");
}

<span id="divt1" style="visibili ty:hidden;posit ion:relative;to p:0;left:0">
<label for="other">Ple ase specify where you heard about us:</label>
<input type="text" size="40" name="other" id="other">
</span>
Mar 2 '06 #1
7 8029
I believe layers are deprecated, or not supported in firefox. You can
use the css method you're using for the IE section (i.e.
style.visibilit y = 'visible' ). You may even be able to consolidate
both methods (IE and Firefox) into one, which would make for cleaner
code :)

Mar 2 '06 #2
Paul Lautman wrote on 02 mrt 2006 in comp.lang.javas cript:
toggleT('divt1' ,'s');
function toggleT(_w,_h) {
if (document.all) { // is IE
IE and FF support support GetElementById and css !!
[and most NS too, but are there any out there?]
if (_h=='s') eval("document. all."+_w+".styl e.visibility='v isible';");
De not use eval() it is evil and not necessary

document.all[_w].style.visibili ty='visible';

will do nicely.
if (_h=='h') eval("document. all."+_w+".styl e.visibility='h idden';");
} else { // is NS?
if (_h=='s') eval("document. layers['"+_w+"'].visibility='sh ow';");
if (_h=='h') eval("document. layers['"+_w+"'].visibility='hi de';");
}


try:

function toggleT(_w,_h) {
var xw = document.getEle mentById(_w)
if (_h == 's')
xw.style.visibi lity = 'visible';
else
xw.style.visibi lity = 'hidden';
}

or even shorter:

function toggleT(_w,_h) {
document.getEle mentById(_w).st yle.visibility =
(_h == 's') ? 'visible' : 'hidden';
}

not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 2 '06 #3
Evertjan. wrote:
try:

function toggleT(_w,_h) {
var xw = document.getEle mentById(_w)
if (_h == 's')
xw.style.visibi lity = 'visible';
else
xw.style.visibi lity = 'hidden';
}

or even shorter:

function toggleT(_w,_h) {
document.getEle mentById(_w).st yle.visibility =
(_h == 's') ? 'visible' : 'hidden';
}

not tested


Thanks for the prompt reply.
I did some more poking around and ended up changing from visibility too
display thus:

document.getEle mentById(_w).st yle.display = 'block';
document.getEle mentById(_w).st yle.display = 'none';

Since these both seem to accomplish the same thing, I wonder what the
difference is between the display and the visible properties and is one of
them better than the other for this application?

Any ideas?

TIA
Paul

Mar 2 '06 #4
"Paul Lautman" <pa**********@b tinternet.com> writes:
I found the toggle function (shown below) and applied it to a form of mine.
It works fine in IE, but in Firefox it appears to fail on the eval lines.
As it should. This script is so old it belives there are only two browsers
out there, IE and Netscape 4. It's a small wonder that the IE branch still
works.

It's also horribly written, even by the standard of its time, using
eval where it is absolutely not necessary.

My suggestion is to scrap it and start fresh.
toggleT('divt1' ,'s');

function toggleT(_w,_h) {
if (document.all) { // is IE
if (_h=='s') eval("document. all."+_w+".styl e.visibility='v isible';");
if (_h=='h') eval("document. all."+_w+".styl e.visibility='h idden';");
} else { // is NS?
if (_h=='s') eval("document. layers['"+_w+"'].visibility='sh ow';");
if (_h=='h') eval("document. layers['"+_w+"'].visibility='hi de';");
}


Ick. Why use "s" or "h" instead of true and false. But that's the least
of this hackery's problems.

My suggestion:

toggleT('divT', true);

function toggleT(elemId, visible) {
document.getEle mentById(elemId ).style.visibil ity =
visible?"visibl e":"hidden";
}

It's not as backwards compatible as possible, failing in IE 4 and
Netscape 4. If these are really important, you can use:

function toggleT(elemId, visible) {
var elem;
if (document.getEl ementById) {
elem = document.getEle mentById(elemId );
} else if (document.all) {
elem = document.all[elemId];
} else if (document.layer s) {
elem = document.layers[elemId];
} else {
return; // give up!
}
(elem.style || elem).visibilit y = visible ? "visible" : "hidden";
}

Not tested :)

Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Mar 2 '06 #5
Paul Lautman said the following on 3/2/2006 3:21 PM:
Evertjan. wrote:
try:

function toggleT(_w,_h) {
var xw = document.getEle mentById(_w)
if (_h == 's')
xw.style.visibi lity = 'visible';
else
xw.style.visibi lity = 'hidden';
}

or even shorter:

function toggleT(_w,_h) {
document.getEle mentById(_w).st yle.visibility =
(_h == 's') ? 'visible' : 'hidden';
}

not tested


Thanks for the prompt reply.
I did some more poking around and ended up changing from visibility too
display thus:

document.getEle mentById(_w).st yle.display = 'block';
document.getEle mentById(_w).st yle.display = 'none';
Since these both seem to accomplish the same thing, I wonder what the
difference is between the display and the visible properties and is one of
them better than the other for this application?


visibility will just hide the element. the display property will remove
it from the flow of the page entirely.

Put this in a test page and view it:
<div>some text</div>
<div style="display: none">Some other text</div>
<div>This text will align right below the some text div</div>
<div>some text</div>
<div style="visibili ty:hidden">Some other text</div>
<div>This text will not align right below the some text div</div>

The only difference in the two is one uses visibility, the other uses
display
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 2 '06 #6
Evertjan. said the following on 3/2/2006 3:13 PM:
Paul Lautman wrote on 02 mrt 2006 in comp.lang.javas cript:
toggleT('divt1' ,'s');


function toggleT(_w,_h) {
if (document.all) { // is IE


IE and FF support support GetElementById and css !!
[and most NS too, but are there any out there?]


IE and FF support getElementById but they only support GetElementById if
you define them yourself <g> :)

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 2 '06 #7
Randy Webb wrote:
visibility will just hide the element. the display property will
remove it from the flow of the page entirely.

Put this in a test page and view it:
<div>some text</div>
<div style="display: none">Some other text</div>
<div>This text will align right below the some text div</div>
<div>some text</div>
<div style="visibili ty:hidden">Some other text</div>
<div>This text will not align right below the some text div</div>

The only difference in the two is one uses visibility, the other uses
display


Ahh yes, I missed that when viewing the page. That is what I wanted to
happen in the first place. Serendipity!

Thanks everyone for such speedy assistance.

Mar 2 '06 #8

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

Similar topics

3
16542
by: earl | last post by:
Hey Say I have two <form> on a page like this : <form action="private.asp" method="post" name="form1"> // code <input type=submit value="submit" name="submit"> </form> <form action="private2.asp" method="post" name="form2">
2
2507
by: Ajai Kumar .R | last post by:
Hai all, I've two or more forms on my app. My requirement is, Have to show the first form asa the user press a button have to hide the first form and show the second form. If the user press the escape key on second form, this should be hidded and should show the first form.... Can some one guide me how to achive this... (MUST USE SHOW & HIDE FORM PROPERTIES). I tried to achive this using the below code but when i check the Windows->Task...
9
2765
by: sergio | last post by:
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">
5
6778
by: Wouter | last post by:
Hi, I had a javscript what does the follow. When a checkbox is yes then i will see a form field. When a checkbox is no i dont see the form field. Can somehelp me for that script ? Greets Wouter
7
29136
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field below the comment with a spell check & submit button. Clicking "Amend" would display the same buttons & text field but pre-populated with the original comment. Using Java Script how do I show / hide the text field in my list of comments but have...
6
4191
by: Norman | last post by:
Hello, I have a working Show / Hide form, that works on FF, but what I would like to do is to be able to display one part when a user clicks on one radio button and display another part when the user clicks on the second radio button - here is the code which just shows / hides the whole form: <script type="text/javascript"> <!-- var dl_elements = new Array('dl_address_country',
1
19073
by: magmike | last post by:
Looking to do sort of the same thing you see on websites, but on access form, where when a value is selected from a drop down list, if it matches the desired value, certain form fields appear. For example, the records in my table are one of three types of records, Owner, Member or Independent. I have fields in the table that only correspond to Owner records and only want those fields showing on the form if the CompanyType is selected as...
3
1936
by: OzNet | last post by:
Hi I have a main form and want to put two subforms on a tabbed control (on the same tab) Subform 1 will display data if it corresponds with the data on the main form. When this is true, subform 2 will be blank Likewise, subform 2 will display data if it corresponds with the data on the main form and when this is true, subform1 will be blank. How can I make the subforms visible only when there is data present?
4
2731
by: Shinee Nag | last post by:
What I am trying to do is add first text field right after a dropdown menu only if the user selects a first option, when a user selects second option then second text field is opened I am new to java script so pls help me.....
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.