473,785 Members | 2,283 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 23 '05 #1
7 1374
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 23 '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 23 '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 23 '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 23 '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 23 '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 23 '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 23 '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
9949
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
9512
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
7897
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...
3
4428
by: Burak Kadirbeyoglu | last post by:
Dear Developers, I have a simple question. There's a textbox and an imagebutton on my page. When I focus on the textbox and hit enter, the imagebutton is being clicked. However, when I click somewher else on the page and hit enter, the imagebutton gets clicked again. How can I unfocus the imagebutton? The script I'm implementing is given below. Thanks in advance, Burak
2
55409
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
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
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
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
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
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.