2 Replies Latest reply on Apr 5, 2013 10:08 AM by sparrowce

    setFocus not working

    sparrowce Level 1

      I have a 'total' field on a purchase order form, am using below custom validation script to ensure the value does not exceed 7500.00.  That part works ok, it gives the error message ok, but I'm trying to get the cursor to go back to the top of the Quantity column (QTY.0), but it doesn't seem to be doing that.  As it is, it throws the cursor to the bottom of the page where the 'total' field is. What am I missing?  Thank you!

       

      if((event.value <= 7500.00)){
      //Valid
      } else {
      app.alert("ERROR: Total exceeds Site PO Limit. Please revise price or quantity.", 3);
      event.rc = false; 
      this.getField("QTY.0").setFocus();
      }
      
        • 1. Re: setFocus not working
          Test Screen Name Most Valuable Participant

          My feeling (may be wrong) is that a validation script is for validating what the user actually types, and belongs on the field where they are typing; if the validation fails, I would expect the focus to stay/move to the validated field.

           

          Sounds more like a job for a calculation script, or for onBlur on each component of the total.

          • 2. Re: setFocus not working
            sparrowce Level 1

            Maybe I do have things backwards. The validation is on the total field, which is on bottom of page, and regardless of which row they are on, once they enter a quantity and/or price that causes the total to exceed amount, it gives the error message and moves the cursor to bottom of page where validated field is, so your expectation is right. I was hoping I could just add the setfocus to end of script like with vba, but am still learning javascript and appreciate the help.  There are 20 rows for potential line items, and the 'exceed' part could happen on any row depending on the values they put in.  Are you saying I'll need to go back to each row and add validation at that point instead of total field?  If so, can you direct me as to how to switch the code around?  Thank you!