By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

Dynamically setting an event.

P: n/a
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="visibility: 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.length == 0 ){
i=0;
}
else {
i=form.xxx.length
};

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

form.xxx.options[i] = new
Option(form.startProcess.options(form.startProcess .selectedIndex).text
+ ' to ' + form.endProcess.options(form.endProcess.selectedIn dex).text,
form.startProcess.options(form.startProcess.select edIndex).value
+ ' to ' + form.endProcess.options(form.endProcess.selectedIn dex).value);
} //ENd Add Item
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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(elementObject, eventName, functionObject)
{
if(document.addEventListener)
{
elementObject.addEventListener(eventName,
function (evt)
{
functionObject(elementObject, evt);
},
false);
}
else if(document.attachEvent)
{
elementObject.attachEvent("on" + eventName,
function ()
{
functionObject(elementObject);
}
)
}
}

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

<script type="text/javascript">
addEvent(document.getElementById("myElementId"),"c hange", 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

P: n/a
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 = functionReference;

<snip> form.endProcess.options(form.endProcess.selectedIn dex).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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.