473,387 Members | 3,684 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,387 software developers and data experts.

Select DOM element by user input

Hi all
I was wondering if this is possible in Javascript.

I want to make a bookmarklet. When a user launches it, it tells the
user to select an element in the page (for example a textarea) with the
mouse. When the user clicks on the textarea, my script gets a reference
of the element that he clicked so i can operate on it. Is it possibile?

Thanks for any input on this, I have some difficulties sorting my ideas
out :)

Best regards

Vortexmind
http://www.vortexmind.net

Oct 20 '06 #1
6 1785
Vortexmind wrote:
Hi all
I was wondering if this is possible in Javascript.

I want to make a bookmarklet. When a user launches it, it tells the
user to select an element in the page (for example a textarea) with the
mouse. When the user clicks on the textarea, my script gets a reference
of the element that he clicked so i can operate on it. Is it possibile?

Thanks for any input on this, I have some difficulties sorting my ideas
out :)

Best regards

Vortexmind
http://www.vortexmind.net
I picked up this bookmarklet a while back... does basically what you ask for...

Put it all back together as one line then feed it through a tidy or similar function
to clean it up real quick.

D.

The purpose of this one is to resize text boxes...

javascript:TxtRsz={formEl:null,adEv:function(t,ev, fn){if(typeof
document.addEventListener!='undefined'){t.addEvent Listener(ev,fn,false)}else{t.attachEvent('on'+ev,f n)}},rmEv:function(t,ev,fn){if(typeof
document.removeEventListener!='undefined'){t.remov eEventListener(ev,fn,false)}else{t.detachEvent('on '+ev,fn)}},init:function(){var
textareas=document.getElementsByTagName('textarea' );for(var
i=0;i<textareas.length;i++){textareas[i].style.cursor='se-resize'}var
inputs=document.getElementsByTagName('input');for( var
i=0;i<inputs.length;i++){if(inputs[i].type=='text'){inputs[i].style.cursor='e-resize'}}TxtRsz.adEv(document,'mousedown',TxtRsz.i nitResize)},initResize:function(event){if(typeof
event=='undefined'){event=window.event}var
target=event.target||event.srcElement;if(target.no deName.toLowerCase()=='textarea'||(target.nodeName .toLowerCase()=='input'&&target.type=='text')){Txt Rsz.formEl=target;TxtRsz.formEl.startWidth=TxtRsz. formEl.clientWidth;TxtRsz.formEl.startHeight=TxtRs z.formEl.clientHeight;TxtRsz.formEl.startX=event.c lientX;TxtRsz.formEl.startY=event.clientY;TxtRsz.a dEv(document,'mousemove',TxtRsz.resize);TxtRsz.adE v(document,'mouseup',TxtRsz.stopResize);try{event. preventDefault()}catch(e){}}},resize:function(even t){if(typeof
event=='undefined'){event=window.event}try{TxtRsz. formEl.style.width=event.clientX-TxtRsz.formEl.startX+TxtRsz.formEl.startWidth+'px' }catch(e){}if(TxtRsz.formEl.nodeName.toLowerCase() =='textarea'){TxtRsz.formEl.style.height=event.cli entY-TxtRsz.formEl.startY+TxtRsz.formEl.startHeight+'px '}},stopResize:function(event){TxtRsz.rmEv(documen t,'mousedown',TxtRsz.initResize);TxtRsz.rmEv(docum ent,'mousemove',TxtRsz.resize);var
textareas=document.getElementsByTagName('textarea' );for(var
i=0;i<textareas.length;i++){textareas[i].style.cursor='text'}var inputs=document.getElementsByTagName('input');for( var
i=0;i<inputs.length;i++){if(inputs[i].type=='text'){inputs[i].style.cursor='text'}}}};TxtRsz.init();

Oct 20 '06 #2
ASM
Vortexmind a écrit :
Hi all
I was wondering if this is possible in Javascript.

I want to make a bookmarklet. When a user launches it, it tells the
user to select an element in the page (for example a textarea) with the
mouse. When the user clicks on the textarea, my script gets a reference
of the element that he clicked so i can operate on it. Is it possibile?
<textarea onclick="alert(this.name)" name="Me">
Oct 20 '06 #3
This is the mozilla only version because of it's length .. IE gags on it...

His IE Version calls up a JS file located on his server.

I can't remember where it came from... sorry.

D.

D.

The purpose of this one is to resize text boxes...

javascript:TxtRsz={formEl:null,adEv:function(t,ev, fn){if(typeof
document.addEventListener!='undefined'){t.addEvent Listener(ev,fn,false)}else{t.attachEvent('on'+ev,f n)}},rmEv:function(t,ev,fn){if(typeof
document.removeEventListener!='undefined'){t.remov eEventListener(ev,fn,false)}else{t.detachEvent('on '+ev,fn)}},init:function(){var
textareas=document.getElementsByTagName('textarea' );for(var
i=0;i<textareas.length;i++){textareas[i].style.cursor='se-resize'}var
inputs=document.getElementsByTagName('input');for( var
i=0;i<inputs.length;i++){if(inputs[i].type=='text'){inputs[i].style.cursor='e-resize'}}TxtRsz.adEv(document,'mousedown',TxtRsz.i nitResize)},initResize:function(event){if(typeof
event=='undefined'){event=window.event}var
target=event.target||event.srcElement;if(target.no deName.toLowerCase()=='textarea'||(target.nodeName .toLowerCase()=='input'&&target.type=='text')){Txt Rsz.formEl=target;TxtRsz.formEl.startWidth=TxtRsz. formEl.clientWidth;TxtRsz.formEl.startHeight=TxtRs z.formEl.clientHeight;TxtRsz.formEl.startX=event.c lientX;TxtRsz.formEl.startY=event.clientY;TxtRsz.a dEv(document,'mousemove',TxtRsz.resize);TxtRsz.adE v(document,'mouseup',TxtRsz.stopResize);try{event. preventDefault()}catch(e){}}},resize:function(even t){if(typeof
event=='undefined'){event=window.event}try{TxtRsz. formEl.style.width=event.clientX-TxtRsz.formEl.startX+TxtRsz.formEl.startWidth+'px' }catch(e){}if(TxtRsz.formEl.nodeName.toLowerCase() =='textarea'){TxtRsz.formEl.style.height=event.cli entY-TxtRsz.formEl.startY+TxtRsz.formEl.startHeight+'px '}},stopResize:function(event){TxtRsz.rmEv(documen t,'mousedown',TxtRsz.initResize);TxtRsz.rmEv(docum ent,'mousemove',TxtRsz.resize);var
textareas=document.getElementsByTagName('textarea' );for(var
i=0;i<textareas.length;i++){textareas[i].style.cursor='text'}var
inputs=document.getElementsByTagName('input');for( var
i=0;i<inputs.length;i++){if(inputs[i].type=='text'){inputs[i].style.cursor='text'}}}};TxtRsz.init();

Oct 20 '06 #4
Vortexmind schrieb:
I want to make a bookmarklet. When a user launches it, it tells the
user to select an element in the page (for example a textarea) with the
mouse. When the user clicks on the textarea, my script gets a reference
of the element that he clicked so i can operate on it. Is it possibile?
Have a look at the "Dom Inspector" extension:
http://www.mozilla.org/projects/inspector/
With this extension you can click on an element in the html document and
the extension shows the element in the document structure tree. I don't
know how it is done but I think you can use similar code.

Björn
Oct 20 '06 #5
no****@comcast.net wrote:
This is the mozilla only version because of it's length .. IE gags on
it...

His IE Version calls up a JS file located on his server.

I can't remember where it came from... sorry.

D.
From themaninblue.com, perhaps?
http://www.themaninblue.com/writing/...ve/2006/08/25/

--Mr. Wilson
Oct 20 '06 #6
Vortexmind schrieb:
I want to make a bookmarklet. When a user launches it, it tells the
user to select an element in the page (for example a textarea) with the
mouse. When the user clicks on the textarea, my script gets a reference
of the element that he clicked so i can operate on it. Is it possibile?
I've had a similar problem. I solved it by adding an event listener to
the whole document. The event.target property is the clicked element:

window.document.addEventListner('click', windowClick, true);

function windowClick(event){
alert('Element clicked: '+event.target);
}

BJörn
Nov 3 '06 #7

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

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
4
by: kaeli | last post by:
All, I have need of a readonly select element that looks and acts disabled to the user. The problem with the disabled attribute is that the value isn't passed to the handler, so I'm using...
1
by: Marek Mänd | last post by:
<select multiple style="height:200px;"> <option>a <option>b </select> Why does Mozilla draw the vertical scrollbar to the SELECT html element? There is plenty of void room below two OPTIONs in...
4
by: bobsawyer | last post by:
I've been building a series of SELECT lists that are populated dynamically using HTTPRequest. Things are going pretty well, and I've got the whole thing working flawlessly in Mozilla/Firebird....
6
by: Omar | last post by:
Hi, In a JSP I have the next: .... codigo = "<select name='" + nombre + "'>\n<option selected value='default'>Escoge</option><option value='todos'>Todos</option>"; if (miRS != null) while...
2
by: frank.sconzo | last post by:
Greetings, I was testing my web application on the Mac/Safari and noticed a problem with the background color of the select input element. Safari doesn't seem to pay any attention to the style I...
16
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
I need a form control for the user to enter currency symbol. A select control seems to be fit for that purpose; but the problem is that the control must appear on the page several times so the...
24
by: fjm | last post by:
Hello all. I am making an interface in php that will draw data from a mysql database. What I have started doing is the html, this is what I know well. php is a different story though. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
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,...
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...

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.