473,770 Members | 4,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can you set focus to a custom custom element?

Phl
hi,

I can use the following code to set focus to standard html elements
but if I try to do the same for a custom element, it seems to complain
that it does not support a focus method. Does anyone know what is the
problem, if there is a work around?

thank you
<SCRIPT language='javas cript'>
document.getEle mentById('" + ctrl.ID + "').focus()
</SCRIPT>
Jul 20 '05 #1
7 9948
ki************@ hotmail.com (Phl) wrote:
I can use the following code to set focus to standard html elements
but if I try to do the same for a custom element, it seems to complain
What is 'it'? A browser? If so, which one?
that it does not support a focus method. Does anyone know what is the
problem, if there is a work around?
A quick test shows that IE6 responds in exactly the same way to
document.getEle mentsByTagName( 'foo')[0].focus()
as it does to
document.getEle mentsByTagName( 'div')[0].focus()

So there seems to be no problem with applying the focus() method to
custom elements. Whether there's any effect from the user's point of
view is another matter.
<SCRIPT language='javas cript'>
document.getEl ementById('" + ctrl.ID + "').focus()
</SCRIPT>


Can you post a URL? Without seeing the rest of your code it's hard to
tell what the problem is. The code you have there looks odd.
There's a good chance that your problem is JavaScript rather than HTML
related, in which case comp.lang.javas cript would offer the best
chance for helpful advice.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net > <http://steve.pugh.net/>
Jul 20 '05 #2
Phl schrieb:
I can use the following code to set focus to standard html elements
Not for all elements in all UAs as both their properties and DOMs differ.
but if I try to do the same for a custom element, it seems to complain
that it does not support a focus method. Does anyone know what is the
problem, if there is a work around?
[...]
<SCRIPT language='javas cript'>
document.getEle mentById('" + ctrl.ID + "').focus()
</SCRIPT>


The proper syntax would be

<script type="text/javascript">
document.getEle mentById(ctrl.I D).focus()
</script>

This works provided that there is an element with an ID equal to the
value of ctrl.ID and document.getEle mentById() returns a reference to
an object that has a focus() method. So this is error-prone and one
should at least write

<script type="text/javascript">
if (typeof document != "undefined"
&& document.getEle mentById)
{
var o = document.getEle mentById(ctrl.I D);
if (o && o.focus)
{
o.focus();
}
}
</script>

(whatever ctrl.ID may be and where it may be defined).
F'up2 comp.lang.javas cript (DO NOT crosspost without Followup-To!)

PointedEars
Jul 20 '05 #3
Phl
here is the custom element I am trying to access:

<prog:ComboBo x id="insert_prjc ode" name="insert_pr jcode"
ParentFormID="F orm1"
ResourcesDirect ory="/webctrl_client/progstudios/1_2/" value="1"
size="5" onchange="__doP ostBack('insert _prjcode','')">
here is the javascript which i used to access but fails , when i try
and use the onfocus method:

<SCRIPT language='javas cript'>var cobj =
document.getEle mentById('inser t_prjcode');
if(!cobj){alert ('failed');}els e{alert('passed ');cobj.focus() ;}

Does this make the problem clearer?

thx
Jul 20 '05 #4
Phl
here is the custom element I am trying to access:

<prog:ComboBo x id="insert_prjc ode" name="insert_pr jcode"
ParentFormID="F orm1"
ResourcesDirect ory="/webctrl_client/progstudios/1_2/" value="1"
size="5" onchange="__doP ostBack('insert _prjcode','')">
here is the javascript which i used to access but fails , when i try
and use the onfocus method:

<SCRIPT language='javas cript'>var cobj =
document.getEle mentById('inser t_prjcode');
if(!cobj){alert ('failed');}els e{alert('passed ');cobj.focus() ;}

Does this make the problem clearer?

thx
Jul 20 '05 #5

"Phl" <ki************ @hotmail.com> wrote in message
news:55******** *************** ***@posting.goo gle.com...
here is the custom element I am trying to access:

<prog:ComboBo x id="insert_prjc ode" name="insert_pr jcode"
ParentFormID="F orm1"
ResourcesDirect ory="/webctrl_client/progstudios/1_2/" value="1"
size="5" onchange="__doP ostBack('insert _prjcode','')">
here is the javascript which i used to access but fails , when i try
and use the onfocus method:

<SCRIPT language='javas cript'>var cobj =
document.getEle mentById('inser t_prjcode');
if(!cobj){alert ('failed');}els e{alert('passed ');cobj.focus() ;}

Does this make the problem clearer?


What is a custom element for, and how does a client even know how to render
it, let alone indicate that it has the focus?

Jul 20 '05 #6
Phl wrote:
here is the custom element I am trying to access:

<prog:ComboBo x id="insert_prjc ode" name="insert_pr jcode"
ParentFormID="F orm1"
ResourcesDirect ory="/webctrl_client/progstudios/1_2/" value="1"
size="5" onchange="__doP ostBack('insert _prjcode','')">
This is not HTML, so what markup language is this?
here is the javascript which i used to access but fails , when i try
and use the onfocus method:
You mean the _focus_ method.
<SCRIPT language='javas cript'>var cobj =
document.getEle mentById('inser t_prjcode');
if(!cobj){alert ('failed');}els e{alert('passed ');cobj.focus() ;}
I have already posted the correct syntax and less
error-prone solution. Why don't you try that first?
Does this make the problem clearer?


Alas not. Besides, if the object has no focus() method, it cannot work.
PointedEars, F'up2 cljs

P.S.:
Please stop crossposting (without followup-To). This has nothing to do
with HTML and thus it is off-topic in ciwa.html.
Jul 20 '05 #7
Phl wrote:
here is the custom element I am trying to access:

<prog:ComboBo x id="insert_prjc ode" name="insert_pr jcode"
ParentFormID="F orm1"
ResourcesDirect ory="/webctrl_client/progstudios/1_2/" value="1"
size="5" onchange="__doP ostBack('insert _prjcode','')">

here is the javascript which i used to access but fails , when i try
and use the onfocus method:

<SCRIPT language='javas cript'>var cobj =
document.getEle mentById('inser t_prjcode');
if(!cobj){alert ('failed');}els e{alert('passed ');cobj.focus() ;}

Does this make the problem clearer?

thx


You aren't using the "onfocus" method, you're using the "focus" method.
However, you aren't testing to see whether the object supports the
focus() method before you attempt to use it.

Start with this:

<script type="text/javascript">
var cobj = document.getEle mentById('inser t_prjcode');
if (cobj) {
alert(cobj.focu s);
}
</script>

If you get no alert, the object isn't being retrieved correctly.

If you get the alert(), but see anything other then:

function focus() {
[native code]
}

then the focus method isn't supported by your object. Even if you get
the text described above, the "native code" may not actually set the
focus, or it may attempt to set the focus, but other issues within the
user agent prevent that from happening. Once you have determined that
the object supports the focus() method, then the proper test for usage
would be:

if (cobj && cobj.focus) {
cobj.focus();
}

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #8

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

Similar topics

4
10440
by: Paul Thompson | last post by:
How do I determine in JavaScript the name of the object that focus is on?
5
1645
by: Stefano | last post by:
Hi, i want set focus element with element.focus() but i have always this exception: "focus() is not a function" Can you help me? Thanks I use Mozilla
7
1373
by: Phl | last post by:
hi, I can use the following code to set focus to standard html elements but if I try to do the same for a custom element, it seems to complain that it does not support a focus method. Does anyone know what is the problem, if there is a work around? thank you
9
9511
by: s_m_b | last post by:
I'm trying to get an <a> element to gain the focus onload, but only get back 'has no properties'. Reading through this ng, its clear that unless the element is within a form, this doesn't happen, but according to the w3 TR on html 4.01, the a element can take onFocus commands, which to me means you can do document.getElementById(element).focus() ? I'm trying to get the focus to a specific paragraph, so the page scrolls to it on loading,...
3
7895
by: Praveen | last post by:
In IE a table element will receive focus when you either tab into it or when you click anywhere within the table. Mainly it fires the onfocus event. This doesn't happen in Mozilla (Firefox and Netscape). Is there any setting or anyother way to force the table element to fire the onfocus and onblur events? Thanks
3
6897
by: VA | last post by:
t=document.getElementById('mytable') is a HTML table with some input fields in its cells Why doesnt t.getElementsByTagName('tr').firstChild.focus; put the focus on that text field? It doesnt give any errors, the focus just doesnt change.
0
2117
by: Vinod. | last post by:
Hi all, I have added browser control to a windows form. I am loading pages having multiple frames. I have noticed that the focus in a text is not maintained when the application is deactivated. I fixed this issue by finding the active element in dom and then setting its focus. If the active element is a frameelement then I get the document of the frameelement and then get the activeelement of that document and set the focus. This works...
2
55398
by: yawnmoth | last post by:
Say I have two input elements and that I wanted to make it so that when the first ones input was what it should be, the focus would automatically be shifted to the next input element. ie. something like... <input onkeyup="if (this.value.length == this.maxlength) document.forms.elements.focus()" value="whatever" maxvalue="x" type="text" /> <input value="whatever" maxvalue="x" type="text" />
4
68049
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between these forms that may make one succeed and another fail? In particular, this.window.focus() fails in Opera 9.10 with an "object not found", and windows.focus() succeeds in Opera 9.10, Firefox 2.02, and IE 7.
0
9439
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,...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7431
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
6690
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
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
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
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.