problem setting focus()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joe

    #1

    problem setting focus()

    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

  • DU

    #2
    Re: problem setting focus()

    joe wrote:[color=blue]
    > Hi Everyone,[/color]

    Hello Charles :)

    could anyone comment on the following problem:[color=blue]
    > 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);[/color]

    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.
    [color=blue]
    > answerbox=docum ent.createEleme nt('input');
    > answerbox.addEv entListener("ch ange",check_ans wer,false);[/color]

    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

    [color=blue]
    > answerbox.style .fontSize=FONTS IZE;
    > answerbox.style .backgroundColo r=COLOR_ANSWBG;
    > answerbox.style .foregroundColo r=COLOR_ANSWFG;[/color]

    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

    [color=blue]
    > answerbox.style .color=COLOR_AN SWFG;
    > answerbox.style .width="100";[/color]

    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
    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


    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)."
    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

    [color=blue]
    > answerbox.style .align="center" ;[/color]

    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..?
    [color=blue]
    > if(n1<13){
    > c01.appendChild (answerbox);
    > answerbox.focus ();//THIS IS THE LINE CALLING FOCUS()****[/color]

    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
    [color=blue]
    > 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>
    >[/color]

    The error message is not entirely conclusive. Which version of Firefox
    (and build number) are you using?
    [color=blue]
    > Line 285 is the "answerbox.focu s();" line.
    >
    > TIA for any help!
    > -Joe
    >[/color]

    DU
    --
    The site said to use Internet Explorer 5 or better... so I switched to
    Firefox 1.0.3 :)

    Comment

    • joe

      #3
      Re: problem setting focus()

      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

      Comment

      • RobB

        #4
        Re: problem setting focus()

        joe wrote:[color=blue]
        > 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[/color]

        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.

        Comment

        • joe

          #5
          Re: problem setting focus()

          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

          Comment

          • DU

            #6
            Re: problem setting focus()

            joe wrote:[color=blue]
            > 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
            >[/color]

            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 :)

            Comment

            • joe

              #7
              Re: problem setting focus()

              roger that -- i'll try it. Thanks-
              joe

              Comment

              Working...