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

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

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

vi************@gmail.com

May 30 '06 #1
1 1653
vi************@gmail.com wrote:
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.

--
Rob
May 31 '06 #2

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

Similar topics

1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
2
by: Paolo Mancini | last post by:
Hi all, I have a page with many different elements: <a href="...."> ... </a>, listboxes, radiobuttons, etc. Can I use javascript to prevent the user from interacting with the page? That is:...
1
by: Trikki | last post by:
Hi, Im very new to Javascript and i'm in the very early learning stages. My question is: I have a web page with 8 links on, i want to disable the left mouse click on 6 of these links but...
9
by: Alan Lane | last post by:
Hello world: Background: Yesterday, January 21, Doug Steele was kind enough to help me out on a Left Join problem. I was trying to return all stores and their Gross Adds for December, 2004...
4
by: fniles | last post by:
I have an ActiveX control in my web page that I tried to access using intranet. I have implemented IObjectSafety in the ActiveX control, and when I created the CAB file using VB Pakage and...
69
by: RC | last post by:
I know how to do this in JavaScript by window.open("newFile.html", "newTarget", "scrollbars=no,resizable=0,width=200,height=200"); The browser will open a new window size 200x200, not allow...
0
by: Douglas J. Badin | last post by:
Hi, The problem with Authorization is it stops at the first match and doesn't permit Grouping. On the Web Site, I am trying to Secure Page Access and SiteNaviagation by implementing the...
1
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I would like to gray out or disable all of page content while a pannel is visible and active. I know there is a way to do this. psudo code 1. click "Join" 2. display panel and disable all other...
4
idsanjeev
by: idsanjeev | last post by:
sir i am creating a page for logout but problems is here if user is logout and click on standard back button then go on previous page so how can restricted it if user is logout then you don't go back...
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...

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.