473,837 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem setting focus()

joe
Hi Everyone, could anyone comment on the following problem:
I have a textbox being appended to a cell in a table, and
am trying to call focus() on like this:

<snip>
c01.removeChild (answerbox);
answerbox=docum ent.createEleme nt('input');
answerbox.addEv entListener("ch ange",check_ans wer,false);
answerbox.style .fontSize=FONTS IZE;
answerbox.style .backgroundColo r=COLOR_ANSWBG;
answerbox.style .foregroundColo r=COLOR_ANSWFG;
answerbox.style .color=COLOR_AN SWFG;
answerbox.style .width="100";
answerbox.style .align="center" ;
if(n1<13){
c01.appendChild (answerbox);
answerbox.focus ();//THIS IS THE LINE CALLING FOCUS()****
tstart=new Date().getTime( );
}
</snip>

And my Firefox JavaScript console generates one of these:

<snip>
Error: [Exception... "'Permissio n denied to get property
XULElement.sele ctedIndex' when calling method:
[nsIAutoComplete Popup::selected Index]" nsresult: "0x8057001e
(NS_ERROR_XPC_J S_THREW_STRING) " location: "JS frame ::
http://asymptopia.org/MathVolcano/mv04.js :: update_display :: line
285" data: no]
Source File: http://asymptopia.org/MathVolcano/mv04.js
Line: 285
</snip>

Line 285 is the "answerbox.focu s();" line.

TIA for any help!
-Joe

Jul 23 '05 #1
6 2031
DU
joe wrote:
Hi Everyone,
Hello Charles :)

could anyone comment on the following problem: I have a textbox being appended to a cell in a table, and
am trying to call focus() on like this:

<snip>
c01.removeChild (answerbox);
Your code does not indicate what is c01, where it comes, etc..

Addendum: I found your webpage
http://asymptopia.org/MathVolcano/mv04.js
http://www.asymptopia.org/MathVolcano/MathVolcano.html
and c01 is a table cell.
None of your webpages will trigger web stnadards compliant rendering
mode in Mozilla or Firefox. I strongly recommend you use strict HTML
4.01 and validate both your markup code and CSS code: that way you avoid
/eliminate at the source non-javascript errors which may influence,
affect your DHTML functioning.
answerbox=docum ent.createEleme nt('input');
answerbox.addEv entListener("ch ange",check_ans wer,false);
I'm not sure you can register an event listener to a dynamically created
element. I don't know.

One thing is for sure: if answerbox is a text input, then you need to
explicitly define it as such:

answerbox.type = "text";

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-62883744

answerbox.style .fontSize=FONTS IZE;
answerbox.style .backgroundColo r=COLOR_ANSWBG;
answerbox.style .foregroundColo r=COLOR_ANSWFG;
foregroundColor is not valid.
Valid properties are listed here:
http://www.w3.org/TR/2000/REC-DOM-Le...CSS2Properties
but color is
http://www.w3.org/TR/2000/REC-DOM-Le...operties-color

answerbox.style .color=COLOR_AN SWFG;
answerbox.style .width="100";
No unit defined. It could be 100mm or it could be 100pc or 100px. This
is a fairly frequent error. Firefox and Mozilla nightly builds report
such error in the javascript console since rv 1.8a4.

"CSS1 and CSS 2.x specifications require that non-zero values must be
specified with a length unit; otherwise, the css declaration will be
ignored."
Using Web Standards in Your Web Pages
Manipulating Document Style and Content
http://www.mozilla.org/docs/web-deve...html#dom_manip

Mozilla Web Author FAQ
"Lengths other than zero should be followed by a proper unit without a
space between the number and the unit (eg. 1.2em)."
http://www.mozilla.org/docs/web-deve...tylenotworking
http://www.mozilla.org/docs/web-developer/faq.html
answerbox.style .align="center" ;
It's most likely

answerbox.style .textAlign = "center";

that you want to use... assuming answerbox is a text input.
...unless you want to horizontally center the input inside the cell..?
if(n1<13){
c01.appendChild (answerbox);
answerbox.focus ();//THIS IS THE LINE CALLING FOCUS()****
Chances are that the focus() method would be supported if the parser
knew which kind of input you want to dynamically create+insert.
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-65996295
tstart=new Date().getTime( );
}
</snip>

And my Firefox JavaScript console generates one of these:

<snip>
Error: [Exception... "'Permissio n denied to get property
XULElement.sele ctedIndex' when calling method:
[nsIAutoComplete Popup::selected Index]" nsresult: "0x8057001e
(NS_ERROR_XPC_J S_THREW_STRING) " location: "JS frame ::
http://asymptopia.org/MathVolcano/mv04.js :: update_display :: line
285" data: no]
Source File: http://asymptopia.org/MathVolcano/mv04.js
Line: 285
</snip>

The error message is not entirely conclusive. Which version of Firefox
(and build number) are you using?
Line 285 is the "answerbox.focu s();" line.

TIA for any help!
-Joe


DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Firefox 1.0.3 :)
Jul 23 '05 #2
joe
DU, Thanks for your reply. I'll pursue a more robust solution
in the long run, but just now I changed the element type of
answerbox to "text" as you suggested, and nothing shows
up at all. It may be a compound problem, in which case re-
working everything is the only soln, but that's what happens
with that change alone. I'm using firefox 1.0.3, also. I like
your .sig quote.
Joe

Jul 23 '05 #3
joe wrote:
Hi Everyone, could anyone comment on the following problem:
I have a textbox being appended to a cell in a table, and
am trying to call focus() on like this:

<snip>
c01.removeChild (answerbox);
answerbox=docum ent.createEleme nt('input');
answerbox.addEv entListener("ch ange",check_ans wer,false);
answerbox.style .fontSize=FONTS IZE;
answerbox.style .backgroundColo r=COLOR_ANSWBG;
answerbox.style .foregroundColo r=COLOR_ANSWFG;
answerbox.style .color=COLOR_AN SWFG;
answerbox.style .width="100";
answerbox.style .align="center" ;
if(n1<13){
c01.appendChild (answerbox);
answerbox.focus ();//THIS IS THE LINE CALLING FOCUS()****
tstart=new Date().getTime( );
}
</snip>

And my Firefox JavaScript console generates one of these:

<snip>
Error: [Exception... "'Permissio n denied to get property
XULElement.sele ctedIndex' when calling method:
[nsIAutoComplete Popup::selected Index]" nsresult: "0x8057001e
(NS_ERROR_XPC_J S_THREW_STRING) " location: "JS frame ::
http://asymptopia.org/MathVolcano/mv04.js :: update_display :: line
285" data: no]
Source File: http://asymptopia.org/MathVolcano/mv04.js
Line: 285
</snip>

Line 285 is the "answerbox.focu s();" line.

TIA for any help!
-Joe


Just a suggestion:

if(n1 < 13)
{
c01.removeChild (answerbox);
answerbox = document.create Element('input' );
answerbox.setAt tribute('type', 'text');
var s = answerbox.style ;
s.width = '100px';
s.fontSize = FONTSIZE;
s.color = COLOR_ANSWFG;
s.textAlign = 'center';
s.backgroundCol or = COLOR_ANSWBG;
answerbox.addEv entListener('ch ange', check_answer, false);
c01.appendChild (answerbox);
setTimeout('ans werbox.focus(); ', 100);
tstart = new Date().getTime( );
}

The focus issue is a bug iirc.

Looks like that conditional should involve the entire process, just a
guess. Make sure answerbox is global (timers execute with global
scope). I'd suggest using replaceChild() for this, instead of
remove/append.

Jul 23 '05 #4
joe
Thanks RobB -- I replaced that piece of code with
yours and thought it fixed it, but unfortunately the
error still occurs. But if it's a bug, then that's
good news. The thing works fine, just those
unsightly error for anyone who happens to look.
Thanks again,
Joe

Jul 23 '05 #5
DU
joe wrote:
DU, Thanks for your reply. I'll pursue a more robust solution
in the long run, but just now I changed the element type of
answerbox to "text" as you suggested, and nothing shows
up at all. It may be a compound problem, in which case re-
working everything is the only soln, but that's what happens
with that change alone. I'm using firefox 1.0.3, also. I like
your .sig quote.
Joe


Btw, just after sending the post, I thought that
answerbox.size= 5;
was a better replacement to
answerbox.style .width="100";

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Firefox 1.0.3 :)
Jul 23 '05 #6
joe
roger that -- i'll try it. Thanks-
joe

Jul 23 '05 #7

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

Similar topics

10
6727
by: CES | last post by:
All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon exiting a form field, if the
0
1776
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not happened always whenever DataSource is set, only called sometimes, in a series of setting DataSource, I could get this setting focus only one time . Can anybody help me how to stop this one. system.windows.forms.dll!
1
2250
by: avnrao | last post by:
Hi, I am facing a problem with control.focus (javascript). Here is the description of the issue. 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on this, will redirect page to Aspx2 which has a Datagrid. PageLoad of Aspx2 displays the DataGrid with existing data filled in and shows a new row (set of text boxes) in the Footer Item. Now, when I set the focus by accessing the first text box in the Footer
0
982
by: dgk | last post by:
I've tried setting the tab order using the tab order tool (VS2005) but when the form finishes loading, the focus is on the tab control and not the first textbox on the form. The textbox is inside a groupbox. If I press Tab, the focus moves to the correct textbox. In fact, I've tried setting focus (txtIND.focus) as the last line in the form load, and still the focus ends up on the tab control itself. With the tab order tool, I first...
1
2068
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
1
5142
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
4
5134
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the child window. The function that is called contains an XMLHttpRequest. My problem is that everything happens as it should, the innerHTML is changed by the results of the XMLHttpRequest and the child window closes. The problem is this, in Firefox,...
1
2314
by: Werner Schmidt | last post by:
Dear group, I have a very strange behaviour: In a loop there are several TextBoxes initialized: TextBox objTextBox = null; // one declaration for-loop // multiple initialisations
14
4594
by: Wayne | last post by:
I posted about this problem over 12 months ago and even after Vista SP1 the problem still exists when running an Access database (A2003 and A2007 tested) under Vista. A workaround was suggested by another group member at that time, but it's hardly ideal. MS should really look at this and fix it. When a form containing a chart is opened the chart object is visible, but no chart data is visible. If any other form is opened over the top...
1
3122
by: Drelus | last post by:
I'm using an Ajax call to open a search box in the page and I want the focus to go to the box automatically. So, in the httpObject.responseText, I tried sending the following in addition to the search box markup: <script type="text/javascript"> document.getElementById('Message').focus(); </script> and, after writing the response using innerHTML, the originating Ajax function calls an eval function to enable the JavaScript, the critical...
0
9852
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...
0
10583
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
10288
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
9420
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
7824
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
5680
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
4481
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
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
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.