focusing on a field using java script

Results 1 to 2 of 2

Thread: focusing on a field using java script

  1. #1
    Join Date
    Dec 1969

    Default focusing on a field using java script

    i am creating a login page with userid and password and a submit button.<BR>what code i have to write so that as soon as i run this asp file the focus should be on the first field and if the user dont enter that field and jump to next field it should give alert message and keep the focus on that field.<BR>i will really appriciate if any on helps me out

  2. #2
    Join Date
    Dec 1969

    Default I guess you have to ...

    &nbsp;<BR>(1)to focus on a field while you load the page<BR>&#060;body ... onload = "javascript: document.form.field.focus();"&#062;<BR><BR>(2)to check if that field has a value, have an onblur javascript function for that field<BR>&#060;input type=text name=username ... onblur="javascript: username_onblur();"&#062;<BR><BR><BR>write a javascript function:<BR>&#060;script language="javascript"&#062;<BR>function username_blur(){<BR>if (document.form.field.value == ""){<BR>alert("please fill out the username");<BR>document.form.field.focus();<BR>}<B R>}<BR><BR>lets say field = text field name<BR>Please check for syntax error in my code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts