473,491 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Onclick handler picking up second click on tag. Why?

Hello -

I have written a small table of contents manager. If an entry has
sub-entries, it has a plus in front of it. If the user clicks on the
plus, the sub-entries are displayed. The table of contents is
displayed in one frame and the pages of the document in the other.
Clicking on a table of contents entry redraws the image in the page
frame.

In order to implement this I have the following structure

<div>
<div id="anch0" class="level0">
<span id="exp0" class="plus" onClick="exp_col('exp0');"
onMouseOver="this.style.cursor = 'pointer';">+</span> 
<a href="link?TOCCHOICE=0" target="RIGHT_FRAME"></a>
<div class="expandable">
<div id="anch1" class="level1">
<span id="exp1" class="plus" onClick="exp_col('exp1');"
onMouseOver="this.style.cursor = 'pointer';">+</span> 
<a href="link?TOCCHOICE=1" target="RIGHT_FRAME"></a>
<div class="expandable">
<div id="anch2" class="level2"><a href="link?TOCCHOICE=2"
target="RIGHT_FRAME"></a></div>
<div id="anch3" class="level2">
<a href="link?TOCCHOICE=3" target="RIGHT_FRAME"></a></div>
....

(I've substituted the word 'link' for the actual links used in the
app, and I've taken out the a tag contents.).

If the span contains a plus, the exp_col function just looks at
the children of the span's parent, finds the expandable one, and sets
its display style to 'block'. It also sets the spans content and class
to 'minus'. Clicking on a minus reverses the process.

My problem is that the first time that I click on a span tag,
nothing happens. If I click again, everything works as advertised. The
first click continues to work until the page is refreshed.

Any ideas what's happening?

Garey Mills

Jan 29 '07 #1
1 2830
On Jan 30, 9:18 am, "garey" <garey.mi...@gmail.comwrote:
Hello -

I have written a small table of contents manager.
It's very difficult to debug code you can't see. Since you posted
HTML only, you seem to think it's an HTML problem. In that case, you
might want to ask in an HTML forum:

comp.infosystems.www.authoring.html
<URL: http://groups.google.com.au/group/
comp.infosystems.www.authoring.html?lnk=li >
If an entry has
sub-entries, it has a plus in front of it. If the user clicks on the
plus, the sub-entries are displayed. The table of contents is
displayed in one frame and the pages of the document in the other.
Clicking on a table of contents entry redraws the image in the page
frame.
There are hundreds, if not thousands of such menus already written,
consider finding one you like and copying it.

>
In order to implement this I have the following structure

<div>
<div id="anch0" class="level0">
<span id="exp0" class="plus" onClick="exp_col('exp0');"
You seem to be passing the ID of the element to the exp_col()
function, which you then probably pass to getElementById. Consider:

<span ... onClick="exp_col(this);"

Now you don't care what the ID is and don't waste resources getting a
reference back to the element that called the function.

onMouseOver="this.style.cursor = 'pointer';">+</span> 
The cursor style should be set in CSS, not using script. This will
set the cursor every time the element mouseover event fires, but will
have zero practical effect after the first time and is no different to
setting it permanently in the CSS other than script disabled/incapable
browsers will show the effect too.

<a href="link?TOCCHOICE=0" target="RIGHT_FRAME"></a>
<div class="expandable">
<div id="anch1" class="level1">
<span id="exp1" class="plus" onClick="exp_col('exp1');"
onMouseOver="this.style.cursor = 'pointer';">+</span> 
<a href="link?TOCCHOICE=1" target="RIGHT_FRAME"></a>
<div class="expandable">
You seem to be missing closing tags for the div elements. You should
post code that can be copied and pasted into a page and "works" to the
extent that it illustrates the issue.
<div id="anch2" class="level2"><a href="link?TOCCHOICE=2"
target="RIGHT_FRAME"></a></div>
<div id="anch3" class="level2">
<a href="link?TOCCHOICE=3" target="RIGHT_FRAME"></a></div>
...

(I've substituted the word 'link' for the actual links used in the
app, and I've taken out the a tag contents.).
You can use CSS to do the + and - thing with images by changing the
class of the element, there are many examples of how to add/remove
class values in the archives and various free libraries. Search for
"add remove class name".
>
If the span contains a plus, the exp_col function just looks at
the children of the span's parent, finds the expandable one, and sets
its display style to 'block'.
Since they are divs, better to toggle between '' (empty string) and
'none'.
It also sets the spans content and class
to 'minus'. Clicking on a minus reverses the process.

My problem is that the first time that I click on a span tag,
nothing happens. If I click again, everything works as advertised. The
first click continues to work until the page is refreshed.

Any ideas what's happening?
Invisible code is hard to debug. :-)

--
Rob

Jan 30 '07 #2

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

Similar topics

4
4608
by: Robert Oschler | last post by:
I have a web page that tracks clicks on certain hyperlinks. I am using attachEvent() to attach to the document onClick handler, for IE browsers. It works fine, except that for about 1 out of every...
2
18540
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
2
2061
by: Peter | last post by:
I would like to use code like the following: this.onclick = function(e) { alert("I'm in the onclick handler"); } But I do not want to wipe out any existing onclick event code. I want to do...
1
2166
by: Michel Bany | last post by:
Hello everybody, I am attaching an onclick event handler to a checkbox, using a <script> tag <script>document.getElementById(id).onclick = ...</script> and I have three questions. 1) In the...
0
1397
by: Janet Collins | last post by:
I have a button on a user control on a form. I have the Click event wired to an event handler. The first time I click the button, the page postsback, but does not invoke my event handler. ...
5
2080
by: Fred.Grieco | last post by:
Hi every body, I have a little pb and I'm turning around : function MyFCTN(var1,var2) { var mytable = document.getElementById("myTBL"); for (var i=myTBL.childNodes.length-1; i>0; i--){...
4
13525
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
2
1513
by: pedestrian via DotNetMonster.com | last post by:
I'm having an issue with the button click event handler. I follow this book example using the single-file method. It is a very simple page with a Button and a label: <script runat="server">...
0
7112
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
6974
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
7146
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,...
0
5448
agi2029
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,...
1
4878
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...
0
4573
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...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
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 ...
1
628
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.