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> 7 8034
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 :)
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)
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
"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.'
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/
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/
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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">
|
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...
|
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">
|
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
|
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...
| |
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',
|
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...
|
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?
|
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.....
|
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...
|
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...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |