field.focus() Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shalini Bhalla
    New Member
    • Dec 2007
    • 190

    field.focus() Problem

    i have written following code for for checking required field .

    Code:
    function validate_required(field,alerttxt)
    {
    with (field)
    {
    if (value==null||value=="")
    {alert(alerttxt);
    [B]focus();[/B]
    return false;}
    else {return true}
    }
    }
    but fucus() is not working .......
    Kindly help ASP
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Don't use with. Just use the field directly: field.focus().

    Comment

    • Shalini Bhalla
      New Member
      • Dec 2007
      • 190

      #3
      Field.focus()

      Still it not works . I have aready tried

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        OK, how are you calling the function? Post a snippet of code.

        Comment

        • clain
          New Member
          • Feb 2007
          • 79

          #5
          hey give an id to the element you want to focus. now use this construct

          [code=javascript]
          document.getEle mentById('id_of _your_element') .focus()
          [/code]
          this will fix your problem.. if it does not fix.i will personally fix it for you..

          enjoy coding/!!!
          Last edited by gits; Dec 9 '08, 09:45 AM. Reason: added code tags

          Comment

          Working...