473,787 Members | 2,928 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically setting an event.

Greeting All:

Time to pick the collective brain cell again. I have a web page that
adds options to a select box on the fly. What I need to do is set the
onDblClick event the same way. I need to call a function when the
user double clicks on anything in the list box.

ANy help would be greatly appreciated.

THanks
David
973-292-8656
I set the object initially as such:
<select style="visibili ty: hidden; border:none;" multiple name="xxx"
id="xxx" ></select>

UPon the click of various other objects on the page, the option(s) are
set this way:

function addItem(form){
var i=0;
if (form.xxx.lengt h == 0 ){
i=0;
}
else {
i=form.xxx.leng th
};

if (form.xxx.style .visibility != 'visible') {
form.xxx.style. visibility = 'visible';
};

form.xxx.option s[i] = new
Option(form.sta rtProcess.optio ns(form.startPr ocess.selectedI ndex).text
+ ' to ' + form.endProcess .options(form.e ndProcess.selec tedIndex).text,
form.startProce ss.options(form .startProcess.s electedIndex).v alue
+ ' to ' + form.endProcess .options(form.e ndProcess.selec tedIndex).value );
} //ENd Add Item
Jul 23 '05 #1
4 1641
In article <9a************ **************@ posting.google. com>,
da***********@t-mobile.com enlightened us with...
Greeting All:

Time to pick the collective brain cell again. I have a web page that
adds options to a select box on the fly. What I need to do is set the
onDblClick event the same way. I need to call a function when the
user double clicks on anything in the list box.

ANy help would be greatly appreciated.


AFAIK, that event is only supported in MSIE.
That said, this is how I add events for NN6 and IE6.
Watch for word-wrapping. Modify element ID, event, and handler appropriately.

/*************** *************** *************** **/
/* jsEvents.js
event handling for IE and NN
*/

function addEvent(elemen tObject, eventName, functionObject)
{
if(document.add EventListener)
{
elementObject.a ddEventListener (eventName,
function (evt)
{
functionObject( elementObject, evt);
},
false);
}
else if(document.att achEvent)
{
elementObject.a ttachEvent("on" + eventName,
function ()
{
functionObject( elementObject);
}
)
}
}

/*************** **END********** *************** **/

<script type="text/javascript">
addEvent(docume nt.getElementBy Id("myElementId "),"change" , myHandler);
</script>

--
--
~kaeli~
Well, aren't we just a flipping ray of sunshine?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
David wrote:
Time to pick the collective brain cell again. I have a web
page that adds options to a select box on the fly. What I
need to do is set the onDblClick event the same way.
I need to call a function when the user double clicks
on anything in the list box.
If you mean double-clicking on an option in a select list then you are
not going to be successful as IE browsers do not recognise any events on
OPTION elements.

In other browsers you might try:-

select.options[index].ondblclick = functionReferen ce;

<snip> form.endProcess .options(form.e ndProcess.selec tedIndex).text,

<snip> ^ ^

I am assuming that you are writing exclusively for IE because you are
parenthesising an argument to the - options - collection (calling it as
a method) instead of bracketing a property name (index).

Richard.
Jul 23 '05 #3
Sorry. I should have said that I ma doing this for an intranet with
everyone happily using IE5.5+.

David Paskiet
908-642-2401

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
Sensei wrote:
Sorry. I should have said that I ma doing this for an
intranet with everyone happily using IE5.5+.

<snip>

Maybe, but IE happily supports bracket notation property accessors (it
has to as they are part of ECMAScript, and specified for use with
collections in the W3D DOM bindings for ECMAScript) in addition to
treating DOM collections as methods/functions.

Even when writing exclusively for IE, if you avoid using Microsoftisms
whenever standard direct alternatives are available you will not acquire
a lot of bad habits that will stand in your way if you are ever called
upon to write cross-browser code (and the attempt to write cross-browser
code will not then give you the impression that the task is harder (and
so more costly) than it really is).

Richard.
Jul 23 '05 #5

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

Similar topics

20
12893
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now obviously, I put the alert("s") part in for debugging purposes, just to make sure the error wasn't in any code I was going to be running. This line works just fine in IE6 but in Firefox it doesn't. However, if I replace that line with the...
2
2929
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have a WebForm with some textboxes, dropdownlists, a panel, imagebutton and so on. When I click on the image button (which was created at design time) I dynamically build a table. In each of row of that new table I put several cells and one cell...
4
3119
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
5
1967
by: Sosh | last post by:
Hi, I can't seem to find much information on this. Please could someone explain to me how to wire up events (selectedIndexChanged) to a bunch of dynamically created controls (Dropdownlists), preferably in C#. I'm sure this should be relatively straighforward, but can't for the life of me figure out a good way of doing it. Many thanks!
2
1697
by: epigram | last post by:
I'm dynamically creating a number of radio buttons on my aspx page based upon data read from a db. Each radio button has autopostback turned on. I'm experiencing two problems. 1) I am reading the db, creating the radio buttons, and setting the checked property (also based upon data in the db) in Page_Load regardless of whether a postback is occurring or not. The page loads and displays correctly each time unless the database is updated...
2
5156
by: Rob Roberts | last post by:
In a VS2005 ASP.NET project, I'm trying to find a way to change which css file is linked in based on the browser type. I'd like to use one css file for IE browsers, and a different one for all other browsers. I'm using a MasterPage. I added a Literal control to the Head section of the MasterPage, and then in the Page_Load event I set its Text property to set up the desired link, like this: StyleSheetLiteral.Text = "<link...
2
2457
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the TemplateColumn dynamically. I persist a DataSet in my Session object and I bind the CheckBox to the DataSet. So far so good. The CheckBoxes show up and the user interacts with them (checks a few, unchecks a few). The problem is that during a postback...
11
11214
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just struggling getting an onClick event to show in the HTML source. Any help would be appreciated. Here is a block of my current code which doesn't work. var tr1 = document.createElement('tr');
4
2976
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a while and it seems it's not possible because the row that gets added with each click won't get recreated after a post back. After all the reading it seems that any dynamically created controls must be created in the Init event to be recreated after...
0
1315
by: theleshie | last post by:
Hi, I am creating an application which dynamically creates forms depending on the information held in a dataset (which also includes the data the application itself uses). As part of dynamically creating these forms, I need to bind controls back to their underlying tables. This has been successful with textboxes, but I am having a lot of difficulty with comboboxes. Setting the datasource to the bindinglist seems to be ok, but I am having...
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
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,...
1
7517
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
6749
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
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...

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.