This has been driving me round the bend for hours and I'm not sure
what I should be googleing for to look for a solution so please help!
When you click a div I want to show another div, then when you either
click on either the first div or the newly shown one it hides it
again. I think I'm on the right track, this is my code...
function openDiv(ddl, options) {
this.ddl_obj = document.getElementById(ddl);
this.options_obj = document.getElementById(options);
this.ddl_obj.onclick = dropdownMenu.prototype.click;
this.options_obj.onclick = dropdownMenu.prototype.click;
}
openDiv.prototype.click = function() {
alert(this);
if ( this.options_obj.style.display == 'none' )
this.options_obj.style.display = 'block';
else
this.options_obj.style.display = 'none';
return true;
};
and at the bottom of the page...
obj = new openDiv('div1','div2');
The problem is when the event is being handled, this in the handler
points to the html object that fired it. I want it to point to the
openDiv object. Am I anywhere near to a solution. As you can
probably tell, javascript is not my best subject. 4 1407
On Jun 10, 3:45 pm, suzanne.bo...@gmail.com wrote:
This has been driving me round the bend for hours and I'm not sure
what I should be googleing for to look for a solution so please help!
When you click a div I want to show another div, then when you either
click on either the first div or the newly shown one it hides it
again. I think I'm on the right track, this is my code...
function openDiv(ddl, options) {
this.ddl_obj = document.getElementById(ddl);
this.options_obj = document.getElementById(options);
this.ddl_obj.onclick = dropdownMenu.prototype.click;
this.options_obj.onclick = dropdownMenu.prototype.click;
}
openDiv.prototype.click = function() {
alert(this);
if ( this.options_obj.style.display == 'none' )
this.options_obj.style.display = 'block';
else
this.options_obj.style.display = 'none';
return true;
};
and at the bottom of the page...
obj = new openDiv('div1','div2');
The problem is when the event is being handled, this in the handler
points to the html object that fired it. I want it to point to the
openDiv object. Am I anywhere near to a solution. As you can
probably tell, javascript is not my best subject.
Use closures.
In OpenDiv, for example(untested):
this.ddl_obj.onclick = function() {this.click()};
---
Geoff
On 10 Jun, 21:43, Geoffrey Summerhayes <sumr...@gmail.comwrote:
On Jun 10, 3:45 pm, suzanne.bo...@gmail.com wrote:
This has been driving me round the bend for hours and I'm not sure
what I should be googleing for to look for a solution so please help!
When you click a div I want to show another div, then when you either
click on either the first div or the newly shown one it hides it
again. I think I'm on the right track, this is my code...
function openDiv(ddl, options) {
this.ddl_obj = document.getElementById(ddl);
this.options_obj = document.getElementById(options);
this.ddl_obj.onclick = dropdownMenu.prototype.click;
this.options_obj.onclick = dropdownMenu.prototype.click;
}
openDiv.prototype.click = function() {
alert(this);
if ( this.options_obj.style.display == 'none' )
this.options_obj.style.display = 'block';
else
this.options_obj.style.display = 'none';
return true;
};
and at the bottom of the page...
obj = new openDiv('div1','div2');
The problem is when the event is being handled, this in the handler
points to the html object that fired it. I want it to point to the
openDiv object. Am I anywhere near to a solution. As you can
probably tell, javascript is not my best subject.
Use closures.
In OpenDiv, for example(untested):
this.ddl_obj.onclick = function() {this.click()};
---
Geoff
I did a quick test of this and it gives a 'this.click is not a
function' error. I'll have another play about with it and look into
closures tomorrow, unfortunately I haven't had time today.
On Jun 11, 6:15 pm, suzanne.bo...@gmail.com wrote:
On 10 Jun, 21:43, Geoffrey Summerhayes <sumr...@gmail.comwrote:
Use closures.
In OpenDiv, for example(untested):
this.ddl_obj.onclick = function() {this.click()};
---
Geoff
I did a quick test of this and it gives a 'this.click is not a
function' error. I'll have another play about with it and look into
closures tomorrow, unfortunately I haven't had time today.- Hide quoted text -
My bad.
this.ddl_obj.onclick = function(e){return function(){e.click()}}
(this);
--
Geoff
On 12 Jun, 01:01, Geoffrey Summerhayes <sumr...@gmail.comwrote:
On Jun 11, 6:15 pm, suzanne.bo...@gmail.com wrote:
On 10 Jun, 21:43, Geoffrey Summerhayes <sumr...@gmail.comwrote:
Use closures.
In OpenDiv, for example(untested):
this.ddl_obj.onclick = function() {this.click()};
---
Geoff
I did a quick test of this and it gives a 'this.click is not a
function' error. I'll have another play about with it and look into
closures tomorrow, unfortunately I haven't had time today.- Hide quoted text -
My bad.
this.ddl_obj.onclick = function(e){return function(){e.click()}}
(this);
--
Geoff
Thanks, that works a treat. Now I just need to read up on closures to
find out why. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bob |
last post by:
Below is sample code that illustrates what I'm trying to do. For sake
of brevity I didn't include the properties of buildBtn that determine
what data to request.
The problem is I never see...
|
by: Andreas |
last post by:
Hi,
we have some problems with the following situation:
A remote application A writes files to a directory monitored by a
FileSystemWatcher-instance in application B. A creates the file
with...
|
by: Michael Johnson Jr. |
last post by:
I am trying to handle a button click event, which updates a web control
table with data. The button is dynamically created in the table itself.
When I call updateTable() in the Page_Load the new...
|
by: Paul Bromley |
last post by:
Can someone give me a very simple example on how to do this? As an example I
have a commaned button in a user control. Once this user control is placed
on a form I want to be able to respond in the...
|
by: Jack Russell |
last post by:
My unstanding of all VB up to and including vb6 is that an event could
not "interrupt" itself.
For instance if you had a timer event containing a msgbox then you would
only get one message.
...
|
by: mxliron |
last post by:
hi all, this code is for a picture viewer. yes, this is my first code
and my first piece of programming so i maybe simply be missing some key
notions here. the problem is: the nav onclick event...
|
by: steve |
last post by:
Hi all,
I want to be able to hirearchally define event delegate (declarations)
WITHIN interfaces.
Unfortunatelly C# 1 doesn't appear to support it.
How does the following look as a...
|
by: Robert |
last post by:
Hello javascript group readers,
I have a question regarding how to prevent memory leaks in Internet
Explorer when using closures. I already knew about the circular
reference problem, and until...
|
by: Snor |
last post by:
I'm attempting to create a lobby & game server for a multiplayer game,
and have hit a problem early on with the server design. I am stuck
between using a threaded server, and using an event driven...
|
by: =?Utf-8?B?U3dhcHB5?= |
last post by:
Can anyone suggest me to pass more parameters other than two parameter for
events like the following?
Event:
Onbutton_click(object sender, EventArgs e)"
Event handler:
button.Click += new...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
| |