473,327 Members | 1,979 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,327 software developers and data experts.

Dynamic onclick changing...

21
I have some code that must change the onclick function of a DIV:
Expand|Select|Wrap|Line Numbers
  1. function navChange(id,auto){
  2.   check = fetchById(id + "More").style.display;
  3.   if(check == "block"){
  4.     showLess(id,auto);
  5.   }
  6.   else{
  7.     showMore(id,auto);
  8.   }
  9. }
  10. function showMore(id,auto){
  11.   fetchById(id + 'Img').src = 'graphics/minus.gif';
  12.   fetchById(id + 'More').style.display = 'block';
  13.   if(auto == "true"){
  14.     fetchById(id).onclick = showLess(id,auto);
  15.   }
  16. }
  17. function showLess(id,auto){
  18.   fetchById(id + 'Img').src = 'graphics/plus.gif';
  19.   fetchById(id + 'More').style.display = 'none';
  20.   if(auto == "true"){
  21.     fetchById(id).onclick = showMore(id,auto);
  22.   }
  23. }
The code is for a menu tree. The 'auto' variable is to determine if the function was called by PHP, and if so, make the onclick event turn into something else.

My problem is that when the function is called by PHP, i get a "too much repetition" error.

Please help quickly, as this is a time sensitive question. I will be working on the while waiting for answers, and will post any further bulletins when they happen.

Thanks in advance,
Nate Kay
Jul 18 '07 #1
3 1726
naurus
21
Ohh! I forgot to mention that the fetchById() function is my own cross-browser version of document.getElementById().
Jul 18 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

the way you set the onclick calls the onclick instantly ... have a close look at it ... you make a function-call ...

you may set the function in quotes to set the handler, like:

Expand|Select|Wrap|Line Numbers
  1. fetchById(id).onclick = 'showLess(id,auto)';
kind regards
Jul 18 '07 #3
naurus
21
hi ...

the way you set the onclick calls the onclick instantly ... have a close look at it ... you make a function-call ...

you may set the function in quotes to set the handler, like:

Expand|Select|Wrap|Line Numbers
  1. fetchById(id).onclick = 'showLess(id,auto)';
kind regards
OHH DUH!!! thanks for pointing that out gits!
Jul 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
3
by: Aaron Gervais | last post by:
I am brand-new to javascript, but after reading some tutorials online I was able to make a dynamic HTML photo gallery in javascript. It works fine in all browsers except IE6 (big surprise). I've...
1
by: kusanagihk | last post by:
To all, I'm working on a javascript to dynamic build a common set of HTML controls. 01) I've used the DOM object to build a <div> tag; then build 1 <input type='button'/> and 1 <input...
7
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The...
2
by: czuvich | last post by:
All, I was wondering if it was possible to change a css class on a page load (somehow). Basically, I am wanting to say this: <div id="myclass" class="a javascriptfunction"> Is this...
22
by: tomb | last post by:
I am generating a form dynamically through AJAX. The form and the data come in very nicely, but my reset button doesn't do anything. There are 3 other buttons that call javascript functions - they...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
1
by: Andre | last post by:
Hi. There is a way, that I can create a dynamic ID in a WebControl. This doesn´t work, but, looks like what I want: <asp:Button ID="btnAdd<%="1"%>" runat="server" Text="Add Resposta"...
1
by: chaitanyadotcom | last post by:
As per my application i need to create tabs using iFrame dynamically. There are totally 4 buttons in my application where for each button i provide a link. Where in it will dynamically create a tab...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.