focus

Discussion in 'Javascript' started by jkstinn, Oct 28, 2003.

  1. jkstinn

    jkstinn Guest

    I apologize for another post about focus, but whatever I try just
    doesn't seem to work. I appreciate any ideas that you could give me on
    getting the focus back to the textbox after tabbing or clicking out.
    Jason

    function checkTime(timeVal) {
    var hr, mn;
    if (timeVal.length != 4)
    {
    alert("Time entered must be 4 characters: ex. 0130.");
    document.setCond.elements['hwtime'].focus();
    }



    <INPUT TYPE="text" NAME="hwtime" ID="hwTime" SIZE=4 MAXLENGTH=4
    VALUE="Time" onfocus='this.value="";'
    onchange='checkTime(this.value);'>
     
    jkstinn, Oct 28, 2003
    #1
    1. Advertising

  2. jkstinn

    Erwin Moller Guest

    jkstinn wrote:

    > I apologize for another post about focus, but whatever I try just
    > doesn't seem to work. I appreciate any ideas that you could give me on
    > getting the focus back to the textbox after tabbing or clicking out.
    > Jason
    >
    > function checkTime(timeVal) {
    > var hr, mn;
    > if (timeVal.length != 4)
    > {
    > alert("Time entered must be 4 characters: ex. 0130.");
    > document.setCond.elements['hwtime'].focus();
    > }
    >
    >
    >
    > <INPUT TYPE="text" NAME="hwtime" ID="hwTime" SIZE=4 MAXLENGTH=4
    > VALUE="Time" onfocus='this.value="";'
    > onchange='checkTime(this.value);'>


    Hi,

    What is setCond?
    Difficult to say without the complete code.

    I am sure the following code works:
    document.forms.yourformnamehere.hwtime.focus();

    where you have to replace yourformnamehere by the name of the form this
    element is in.

    Please also check you are not accidentally using the same formname and
    elementname twice.
    Why are you using an ID and a name? (Just curious)
    You could also try to remove the onfocus='this.value="";' and place that in
    the function BEFORE the focus-command.

    Hope that helps.
    Regards,
    Erwin Moller
     
    Erwin Moller, Oct 28, 2003
    #2
    1. Advertising

  3. jkstinn

    jkstinn Guest

    Erwin Moller <> wrote in message news:<3f9e34f1$0$58707$4all.nl>...
    > jkstinn wrote:
    >
    > > I apologize for another post about focus, but whatever I try just
    > > doesn't seem to work. I appreciate any ideas that you could give me on
    > > getting the focus back to the textbox after tabbing or clicking out.
    > > Jason
    > >
    > > function checkTime(timeVal) {
    > > var hr, mn;
    > > if (timeVal.length != 4)
    > > {
    > > alert("Time entered must be 4 characters: ex. 0130.");
    > > document.setCond.elements['hwtime'].focus();
    > > }
    > >
    > >
    > >
    > > <INPUT TYPE="text" NAME="hwtime" ID="hwTime" SIZE=4 MAXLENGTH=4
    > > VALUE="Time" onfocus='this.value="";'
    > > onchange='checkTime(this.value);'>

    >
    > Hi,
    >
    > What is setCond?
    > Difficult to say without the complete code.
    >
    > I am sure the following code works:
    > document.forms.yourformnamehere.hwtime.focus();
    >
    > where you have to replace yourformnamehere by the name of the form this
    > element is in.
    >
    > Please also check you are not accidentally using the same formname and
    > elementname twice.
    > Why are you using an ID and a name? (Just curious)
    > You could also try to remove the onfocus='this.value="";' and place that in
    > the function BEFORE the focus-command.
    >
    > Hope that helps.
    > Regards,
    > Erwin Moller

    Erwin

    setCond is the name of my form. I was using ID and names when I was
    trying to access an element from different ways trying to get the
    thing to work. I went ahaed and took out all the IDs', as you had said
    that maybe I had a naming problem. That still didn't work. I was using
    onchange to test the text for correct information. When I changed the
    onchange to onblur, the focus() would work. What is the difference
    between the onchange and onblur that would make the focus work?

    Thank you for your help.

    Jason
     
    jkstinn, Oct 29, 2003
    #3
  4. jkstinn

    Erwin Moller Guest


    >
    > setCond is the name of my form. I was using ID and names when I was
    > trying to access an element from different ways trying to get the
    > thing to work. I went ahaed and took out all the IDs', as you had said
    > that maybe I had a naming problem. That still didn't work. I was using
    > onchange to test the text for correct information. When I changed the
    > onchange to onblur, the focus() would work. What is the difference
    > between the onchange and onblur that would make the focus work?


    The difference is that onBlur means something like: "Loosing the focus"
    and on change means: "changing the value"

    > You could also try to remove the onfocus='this.value="";' and place that

    in the function BEFORE the focus-command.

    Did you try that?

    >
    > Thank you for your help.
    >
    > Jason


    Good luck!

    Regards,
    Erwin
     
    Erwin Moller, Oct 29, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason
    Replies:
    4
    Views:
    1,635
    Jason
    May 7, 2007
  2. Replies:
    2
    Views:
    344
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  3. Roger
    Replies:
    3
    Views:
    338
  4. Jeff

    manual focus vs. focus()

    Jeff, May 20, 2007, in forum: Javascript
    Replies:
    4
    Views:
    183
  5. Spizzat2
    Replies:
    2
    Views:
    184
    Spizzat2
    Jan 9, 2008
Loading...

Share This Page