Is focus the problem?

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

    #1

    Is focus the problem?

    Yes, I am new to javascript. I have a page with six boxes for 10 goals.
    Because of the other tools, I am using, I cannot use a select or radio
    button for each one. I have this script that works to check the valid
    values for each field. It does not go back to the field with the error
    when I get done. My alert tells me I have the right names at this
    point. Any thoughts?

    Many thanks.

    <!-- Begin
    function checkGrade(objV alue,objName) {
    var checkValue = objValue;
    var checkName = objName;
    var evalmeth = "0123M";
    var pos = evalmeth.indexO f(checkValue);



    if (pos < 0 ) {
    alert(pos+":"+e valmeth+":"+che ckValue+":"+che ckName);
    form.checkName. select();
    form.checkName. focus();
    return false;
    }
    else {
    return true;
    }
    }
    // End -->

    Enter a value from 1 to 5: <input type="text" name="EvalDT1" size="20"
    onchange="check Grade(this.valu e,this.name)">< BR>

  • Joakim Braun

    #2
    Re: Is focus the problem?

    "David" <Taylordh@gmail .com> skrev i meddelandet
    news:1106166451 .828848.34680@f 14g2000cwb.goog legroups.com...[color=blue]
    > Yes, I am new to javascript. I have a page with six boxes for 10 goals.
    > Because of the other tools, I am using, I cannot use a select or radio
    > button for each one. I have this script that works to check the valid
    > values for each field. It does not go back to the field with the error
    > when I get done. My alert tells me I have the right names at this
    > point. Any thoughts?
    >
    > Many thanks.
    >
    > <!-- Begin
    > function checkGrade(objV alue,objName) {
    > var checkValue = objValue;
    > var checkName = objName;
    > var evalmeth = "0123M";
    > var pos = evalmeth.indexO f(checkValue);
    >
    >
    >
    > if (pos < 0 ) {
    > alert(pos+":"+e valmeth+":"+che ckValue+":"+che ckName);
    > form.checkName. select();[/color]

    Where is form defined?
    [color=blue]
    > form.checkName. focus();[/color]

    Where is form defined?

    Joakim Braun


    Comment

    • David

      #3
      Re: Is focus the problem?

      I am testing the function in a small file that does not do anything.
      Here is the entire body.

      <body>
      <form name="myForm" action="tryjs_s ubmitpage.htm" >
      Enter a value from 1 to 5: <input type="text" name="EvalDT1" size="20"
      onchange="check Grade(this.valu e,this.name)">< BR>
      Enter a value from 1 to 5: <input type="text" name="EvalDT2" size="20"
      onchange="check Grade(this.valu e,this.name)">< BR>
      Enter a value from 1 to 5: <input type="text" name="EvalDT3" size="20"
      onchange="check Grade(this.valu e,this.name)">< BR>
      Enter a value from 1 to 5: <input type="text" name="EvalDT4" size="20"
      onchange="check Grade(this.valu e,this.name)">< BR>
      Enter a value from 1 to 5: <input type="text" name="EvalDT5" size="20"
      onchange="check Grade(this.valu e,this.name)">< BR>
      <input type="submit" value="Submit">
      </form>
      </body>

      Comment

      • Mick White

        #4
        Re: Is focus the problem?

        David wrote:
        [color=blue]
        > Yes, I am new to javascript. I have a page with six boxes for 10 goals.
        > Because of the other tools, I am using, I cannot use a select or radio
        > button for each one. I have this script that works to check the valid
        > values for each field. It does not go back to the field with the error
        > when I get done. My alert tells me I have the right names at this
        > point. Any thoughts?
        >
        > Many thanks.
        >
        > <!-- Begin
        > function checkGrade(objV alue,objName) {
        > var checkValue = objValue;
        > var checkName = objName;
        > var evalmeth = "0123M";
        > var pos = evalmeth.indexO f(checkValue);
        >[/color]

        Why are you declaring all thesevariables?

        var pos="0123M".ind exOf(objValue)

        [color=blue]
        > if (pos < 0 ) {
        > alert(pos+":"+e valmeth+":"+che ckValue+":"+che ckName);
        > form.checkName. select();
        > form.checkName. focus();[/color]
        This won't work

        Why not pass the form object itself as a parameter rather than its name?
        checkGrade(this .value,this)
        then:
        objName.select( );objName.focus ();[color=blue]
        > return false;
        > }
        > else {[/color]

        No "else" needed here, nor return [true],[color=blue]
        > return true;
        > }
        > }
        > // End -->
        >
        > Enter a value from 1 to 5: <input type="text" name="EvalDT1" size="20"
        > onchange="check Grade(this.valu e,this.name)">< BR>
        >[/color]
        Mick

        Comment

        • David

          #5
          Re: Is focus the problem?

          Cool. I will give it a try tomorrow. I have had a hard time finding
          good, readable materials that cover all the bases.

          David

          Comment

          • David

            #6
            Re: Is focus the problem?

            I am not sure what I am missing. The alert displays all the right
            values when there is an error, but the focus and select statements
            appear to be ignored.
            David

            <head>
            <script type="text/javascript">
            // allowed grades
            var evalmeth = "0123M";

            <!-- Begin
            function checkGrade(objV alue,objName) {
            var checkValue = objValue;
            var pos = evalmeth.indexO f(checkValue);

            if (pos < 0 ) {
            alert(pos+":"+e valmeth+":"+che ckValue+":"+obj Name.name);
            objName.select( );objName.focus ();
            }
            }
            // End -->


            </script>
            </head>

            <body>
            <form name="myForm" action="tryjs_s ubmitpage.htm" >
            Enter a value from 1 to 5: <input type="text" name="grade01" size="01"
            onchange="check Grade(this.valu e,this)"><BR>
            Enter a value from 1 to 5: <input type="text" name="grade02" size="01"
            onchange="check Grade(this.valu e,this)"><BR>
            Enter a value from 1 to 5: <input type="text" name="grade03" size="01"
            onchange="check Grade(this.valu e,this)"><BR>
            Enter a value from 1 to 5: <input type="text" name="grade04" size="01"
            onchange="check Grade(this.valu e,this)"><BR>
            Enter a value from 1 to 5: <input type="text" name="grade05" size="01"
            onchange="check Grade(this.valu e,this)"><BR>
            <input type="submit" value="Submit">
            </form>
            </body>

            </html>

            Comment

            • Mick White

              #7
              Re: Is focus the problem?

              David wrote:
              [color=blue]
              > I am not sure what I am missing. The alert displays all the right
              > values when there is an error, but the focus and select statements
              > appear to be ignored.
              > David
              >
              > <head>
              >[/color]


              <script type="text/javascript">
              // allowed grades
              var evalmeth = "0123M";
              function checkGrade(objV alue,objName) {
              var pos = evalmeth.indexO f(objValue);
              if (pos < 0 ) {
              alert(pos+":"+e valmeth+":"+obj Value+":"+objNa me.name);
              objName.select( );objName.focus ();
              }
              }
              </script>

              works for me (FF)
              Mick[color=blue]
              > </head>
              >
              > <body>
              > <form name="myForm" action="tryjs_s ubmitpage.htm" >
              > Enter a value from 1 to 5: <input type="text" name="grade01" size="01"
              > onchange="check Grade(this.valu e,this)"><BR>
              > Enter a value from 1 to 5: <input type="text" name="grade02" size="01"
              > onchange="check Grade(this.valu e,this)"><BR>
              > Enter a value from 1 to 5: <input type="text" name="grade03" size="01"
              > onchange="check Grade(this.valu e,this)"><BR>
              > Enter a value from 1 to 5: <input type="text" name="grade04" size="01"
              > onchange="check Grade(this.valu e,this)"><BR>
              > Enter a value from 1 to 5: <input type="text" name="grade05" size="01"
              > onchange="check Grade(this.valu e,this)"><BR>
              > <input type="submit" value="Submit">
              > </form>
              > </body>
              >
              > </html>
              >[/color]

              Comment

              • David

                #8
                Re: Is focus the problem?

                Sigh. It highlights the bad field, but the cursor (focus) goes to the
                next field. Am I expecting too much?

                Comment

                • Mick White

                  #9
                  Re: Is focus the problem?

                  David wrote:
                  [color=blue]
                  > Sigh. It highlights the bad field, but the cursor (focus) goes to the
                  > next field. Am I expecting too much?
                  >[/color]
                  Prolly
                  Mick.

                  Comment

                  • David

                    #10
                    Re: Is focus the problem?

                    Many thanks for your help. I will carry on!

                    Comment

                    Working...