Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / May 2006



Tip: Looking for answers? Try searching our database.

To allow left click only on some elements of web page NOT all elements

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vikas.khengare@gmail.com - 30 May 2006 14:55 GMT
Hi friends

I want to allow left click only on some controls but not on all
controls like textbox/span elements.

I have near about 30+ HTML controls on my web page. then It's bad idea
that I will add listeners to some of them and not to all. if I want it
for >20 then I should required 20 lines for adding listeners to that
controls only.

So Is there any smart way to do that ie Except 5 comtrols I will left
click on remaining elements.

Thanks in advance

>From
vikas.khengare@gmail.com
RobG - 31 May 2006 10:26 GMT
> Hi friends
>
>  I want to allow left click only on some controls but not on all
> controls like textbox/span elements.

What do you mean by 'textbox'?  Is that an input type text, or a
textarea?  Left-click on any of those elements does nothing by default,
you need to add an onlcick attribute for something to happen, and then
only if JavaScript is available.

> I have near about 30+ HTML controls on my web page. then It's bad idea
> that I will add listeners to some of them and not to all.

Why?  There is no need to add listeners to all elements just because one
or two have them.

> ...   if I want it
> for >20 then I should required 20 lines for adding listeners to that
> controls only.

And your problem with that is?  If the code is short, say just calling a
function with one or two parameters, it is the most common way to do it.

> So Is there any smart way to do that ie Except 5 comtrols I will left
> click on remaining elements.

You can use script to add onclick attributes, it means that users
without JavaScript don't have useless attributes in their HTML (though
it's not all that common, most prefer to just add the code to the HTML).

It means that onclick attributes probably aren't added until after the
document has loaded, so it sometimes seems inconsistent on slow loading
sites.

You can use something like:

  function someFn(){ ... }

  function initOnclicks()
  {
    if (!document.getElementById) return;

    var el;
    var idArray = ['id01','id02',...];

    for (var i=0, len=idArray.length; i<len; i++){
      el = document.getElementById(idArray[i]);

      if (el) {
        el.onclick = someFn;
      }
    }
  }

  window.onload = initOnclicks;

Or call the initClicks() function just after the last of the elements
that need an onclick has loaded.

Signature

Rob

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.