How can I get the focus set on a text box that fails validation ? Here is my invocation of the Validate routine.
Me.txtDUNSNo.Attributes.Add("onChange", "ValidateDUNS(this)"
When bad data is typed in, my error msg shows nicely in the status bar but the .focus and .select methods appear to be ignored. My goal is to trap the error and return the cursor to the bad data with the bad data highlighted. This code works in an ASP environment but fails to put focus and select in .Net.
Hardcoding the element name appears to work as a circumvention but I
am trying for generalized scripts that do not restrict the User
Interface into naming text boxes consistently. All my ValidateXXXX
functions reside on a .JS file in the HEAD of the page:
<HEAD>
<script language="javascript" src="../Scripts/Validate.js"></script>
</HEAD>
Thanks in advance to you all. I am using IE6. Here is a sample
function from the .JS page.
function ValidateDUNS(field)
{
var valid = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var temp
inputStr = field.value
thename = field.name
if ( inputStr.length != 9 && inputStr.length != 13)
{
msgDUNS= "\nDUNS number must be at least 9 or 13 characters long."
window.status = msgDUNS
field.focus()
field.select()
}
else{window.status=""
msgDUNS="" }
}
Post
Me.txtDUNSNo.Attributes.Add("onChange", "ValidateDUNS(this)"
When bad data is typed in, my error msg shows nicely in the status bar but the .focus and .select methods appear to be ignored. My goal is to trap the error and return the cursor to the bad data with the bad data highlighted. This code works in an ASP environment but fails to put focus and select in .Net.
Hardcoding the element name appears to work as a circumvention but I
am trying for generalized scripts that do not restrict the User
Interface into naming text boxes consistently. All my ValidateXXXX
functions reside on a .JS file in the HEAD of the page:
<HEAD>
<script language="javascript" src="../Scripts/Validate.js"></script>
</HEAD>
Thanks in advance to you all. I am using IE6. Here is a sample
function from the .JS page.
function ValidateDUNS(field)
{
var valid = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var temp
inputStr = field.value
thename = field.name
if ( inputStr.length != 9 && inputStr.length != 13)
{
msgDUNS= "\nDUNS number must be at least 9 or 13 characters long."
window.status = msgDUNS
field.focus()
field.select()
}
else{window.status=""
msgDUNS="" }
}
Post