focus problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jens Körte

    focus problems

    Hi NG!

    I encountered some strange behaviour when using focus()

    I use a form with several input-fields. A user can enter stuff. After
    entering I want to check the value, i.e. that a number is only a
    number etc.
    I therefore started editing a Javascript. For test purposes it only
    popup a message and sets the focus. In fact this is what I want to do,
    but the scipt isn't it doing right.

    Here is the script:

    <script language=JavaSc ript>
    function check(wert)
    {
    switch (wert)
    {
    case "Firma":
    if (document.Anmel dungsform.Firma .value == '')
    {
    alert("Bitte geben Sie Ihre Firma ein...");
    document.Anmeld ungsform.Firma. focus();
    }
    break;
    case "Vorname":
    if (document.Anmel dungsform.Vorna me.value == '')
    {
    alert("Bitte geben Sie Ihren Vornamen ein...");
    document.Anmeld ungsform.Vornam e.focus();
    }
    break;
    case "Nachname":
    if (document.Anmel dungsform.Nachn ame.value == '')
    {
    alert("Bitte geben Sie Ihren Nachnamen ein...");
    document.Anmeld ungsform.Nachna me.focus();
    }
    break;
    }
    }
    </script>

    And now the HTML-Part
    <form name="Anmeldung sform" method="POST" action="mailer. php">
    <p>Firma:
    <input type="text" name="Firma" onChange="check ('Firma')">
    <br>
    Ansprechpartner :<br>
    Vorname:
    <input type="text" name="Vorname" onChange="check ('Vorname')">
    <br>
    Nachname:
    <input type="text" name="Nachname" onChange="check ('Nachname')">
    <br>
    </form>


    Ths thing that happen is, that after entering noting in field 1
    nothing happens. Focus changes to field 2 and no popup is shown. This
    happens to all of the fields.
    When I enter a value and then deletes the value I encounter no changes
    of the shown behaviour.
    Only if I enter a value, move to the next field, go back and delete
    the value and the force to go to the nect field I get a popup. After
    closing the popup the focus remains on the next field, i.e. it doesn't
    jump back to the field where the user have to make changes.
    I tried this script mainly on Mozilla, but also on IE.
    Please help me

    Jens Körte
  • Michael Winter

    #2
    Re: focus problems

    On Tue, 02 Nov 2004 11:53:18 +0100, Jens Körte <jk060674@gmx.d e> wrote:
    [color=blue]
    > Hi NG![/color]

    Hello. :)
    [color=blue]
    > I encountered some strange behaviour when using focus()[/color]

    The focus method isn't the problem.

    [snip]
    [color=blue]
    > <script language=JavaSc ript>[/color]

    (This won't affect the outcome, by the way.)

    The language attribute is deprecated and has been for about six years! Use
    the (required) type attribute, instead:

    <script type="text/javascript">

    [snip]
    [color=blue]
    > When I enter a value and then deletes the value I encounter no changes
    > of the shown behaviour.
    > Only if I enter a value, move to the next field, go back and delete the
    > value and the force to go to the nect field I get a popup.[/color]

    In the first case, the value is edited, yes, but it hasn't actually
    changed. The value of the control when focus was gained was the same as
    when focus was lost. That is how "change" is determined, and why
    validation should occur (primarily) when the form is submitted (both
    server- and client-side).

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...