473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

toggle question

I wondered if anyone would give me code- I think it would be easy, but
I'm a complete newbie. What I want to do is to show many tables in a
brief truncated format and then for each table offer the user the
ability to toggle so they can see the full content of each table
individually. The code I got from the net below works fine for *one*
table but when I try to add a 2nd table it does not work. How can I
apply this toggle individually to each table?

<html>
<script>
function toggle(e) {
if (e.style.displa y == "none") {
e.style.display = "";
}
else {
e.style.display = "none";
}
}
</script>

<table border=2px><tr> <td>
aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaa<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
<div id=aa style="display: none"> </a>
ccccccccccccccc ccccccccccccccc ccccccccccccccc ccc<br>
ddddddddddddddd ddddddddddddddd ddddddddddd<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
</div>
</td></tr></table>
<a href=javascript :toggle(aa)><b> see more</b></a>
<!-- If I add this table below, it does not work -->
<table border=2px><tr> <td>
aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaa<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
<div id=aa style="display: none"> </a>
ccccccccccccccc ccccccccccccccc ccccccccccccccc ccc<br>
ddddddddddddddd ddddddddddddddd ddddddddddd<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
</div>
</td></tr></table>
<a href=javascript :toggle(aa)><b> see more</b></a>
</html>
Jul 23 '05 #1
2 2284
Ivo
"leegold2" wrote
<html>
<script>
For validation, you need the type attribute. The tag should look like:

<script type="text/javascript">
<table border=2px><tr> <td>
The border attribute of table elements takes a numerical value without "px"
or other units. Also consider putting all your atribute values in quotes. It
will be required in future HTML versions, and helps avoiding confusing today
already. Like so:

<table border="2">
<div id=aa style="display: none"> </a>
What 's that closing </a> tag about? You 're not posting invalid HTML, are
you? Please run your code through a validator such as <URL:
http://validator.w3.org/ > before taking it to Usenet to avoid
disappointment. And again, try putting quotes around the id value, just like
you did with the style value.
<a href=javascript :toggle(aa)><b> see more</b></a>
Don't use "javascript :" as a pseudo-protocol, instead put the script in an
onclick event handler. See this newsgroup's FAQ:
<URL: http://jibbering.com/faq/#FAQ4_24 >
<!-- If I add this table below, it does not work -->
<table border=2px><tr> <td>
aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaa<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
<div id=aa style="display: none"> </a>


What! Another element with "aa" as its id? Remember id's should be unique on
a page. It is what they are all about, it is what they were invented for.

None of the remarks above actually have anything to do with the problem you
describe, except perhaps the double id and the non-quoting of attribute
values. You pass a bald aa to the toggle function, but there is no such
variable. There is an element with "aa" as its id, and that is what you want
to give to the function. Like so:

<a href="#" onclick="toggle (document.getEl ementById('aa') );return false">

It 's not the most efficient way of coding, but should get you on the way.
--
Ivo
Jul 23 '05 #2
leegold2 wrote:
I wondered if anyone would give me code- I think it would be easy, but
I'm a complete newbie. What I want to do is to show many tables in a
brief truncated format and then for each table offer the user the
ability to toggle so they can see the full content of each table
individually. The code I got from the net below works fine for *one*
table but when I try to add a 2nd table it does not work. How can I
apply this toggle individually to each table?

<html>
<script>
function toggle(e) {
if (e.style.displa y == "none") {
e.style.display = "";
}
else {
e.style.display = "none";
}
}
</script>

<table border=2px><tr> <td>
aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaa<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
<div id=aa style="display: none"> </a>
ccccccccccccccc ccccccccccccccc ccccccccccccccc ccc<br>
ddddddddddddddd ddddddddddddddd ddddddddddd<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
</div>
</td></tr></table>
<a href=javascript :toggle(aa)><b> see more</b></a>
<!-- If I add this table below, it does not work -->
<table border=2px><tr> <td>
aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaa<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
<div id=aa style="display: none"> </a>
ccccccccccccccc ccccccccccccccc ccccccccccccccc ccc<br>
ddddddddddddddd ddddddddddddddd ddddddddddd<br>
eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeee<br>
</div>
</td></tr></table>
<a href=javascript :toggle(aa)><b> see more</b></a>
</html>

Give your div tags unique ID's as they are required to be.
Pass the ID of the div tags as a string, not as a variable.
toggle('aa')
toggle('bb')
Read the Group FAQ with regards to href="javascrip t:

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

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

Similar topics

11
4806
by: MLH | last post by:
Why is that? If I choose the tiny check boxes which are hard to hit with a mouse, it works fine. But option buttions, shich can be sized big enough for people with limited sight and dexterity to hit - they don't work at all. Its true. I created 'em with the built-in wizard furnished with Access 97 but they do not work. I put 12 of 'em in the group, labeled the months of the year and giving
4
4342
by: Neil Coleclough | last post by:
I am constructing a database to process product returns for my Company. I have a number of toggle buttons to identify the stage to which each return has been processed. For example, clicking the first button confirms that the goods are now in our building awaiting initial processing. This button then fires off an email to our warehouse staff alerting them to the fact. I want to restrict these buttons to single use, so that once the email...
5
3439
by: Steven | last post by:
Can anyone tell me how to toggle the "Caps Lock" key? Thanks in advance
2
7957
by: Mel | last post by:
Hi, is there any way I can implement toolstrip toggle button simular to the MS Word alignment button? if one toggle button already pressed down, if user click on the "pushed down button", the other toggle button will push down and the "pushed down button" will push up. I have trying to find groupID for toolstrip button, but seem like they don't have it. I hope anyone can help my question, thank you very much.
4
8954
by: deko | last post by:
Basic question about checking the value of Toggle/Check/Combo/OptionGroups.... Checking like this: If Me!chkCheckBox Then ... End If and like this:
2
3143
by: Kingo | last post by:
Hi, First, please forgive my terrible knowledge of JS! I haven't used it in years. I am trying to create a Help page where a new question is on each line, and when clicking on the question, the answer is written below it. Click on the question again removes the answer. (Basically the Q/A is being toggled).
50
28269
by: sksoule | last post by:
Hi, Can anyone please tell me how to toggle a nth bit. For example, I am having a variable which is of 8 bits. I want to toggle the nth bit. Regards, Santosh
6
4011
by: ethanhines | last post by:
I am trying to dynamically change the value of a filed using a toggle button in a form it is not a yes or no question. I want it to change a value in a table based on it"s state. Toggled on="6 inches" Toggled off=<null>. I want to more then one toggle button on the form each one dynamically changing the value of the table in real time. How do I do this?
1
1954
by: swiftouch | last post by:
I'm getting an error message in FF2.0: document.getElementById(toggle) has no properties The goal of the script is, when I hover my mouse over an image, to make one div element visible while making all the others div elements in the array, hidden. thisDocId is the element to avoid hiding. This is the script: <script>
0
8685
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
8631
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
8341
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,...
0
8490
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 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...
1
6112
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
5570
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();...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
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
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.