GessWurker
asked on
Modify validation script to set focus on field in tabbed form
I'm using the script at bottom to validate a particular field. The problem is: I don't know how to get to focus on a field in the first tab of a tabbed form.
I'm trying to get there with this -- setTimeout( function() { $( '#tabs-0' ).focus() }, 500 );
but it doesn't work.
Here's how the .NET form begins...
<div class="divider"> </di v><table id="tblControls" border="0" cellpadding="2"><tr id="ctl00_ctl00_row1_cntrl ID_15290">
<script type="text/javascript" language="javascript"> $(document).ready(function (){ $("#tabbed").tabs(); }); </script> <div id="tabbed"> <ul> <li><a href="#tabs-0">Tab One</a></li> <li><a href="#tabs-1">End Tabs</a></li> <li><a href="#tabs-2">Medical Before Enlistment</a></li> </ul><div id="tabs-0" class="tabs"><table><tr></ td>
</tr>
...
<div id="tabs-0" class="tabs">
Here's the field I need to set focus to if the date format is incorrect:
...
<input name="ctl00$ctl00$cntrlID_ 10724" type="text" value="Dec 11, 1914" id="ctl00_ctl00_cntrlID_10 724" class="k-textbox" onkeypress="if(typeof(Chec kForFormSu bmit)== 9;function '){ return CheckForFormSubmit(event); }" style="width:100px;" />
Here's the script I'm validating with, which includes the focus problem:
function validate() {
var theForm = document.forms['aspnetForm '];
if (!theForm) {
theForm = document.aspnetForm;
}
var emptyString = /^\s*$/ ;
var dmmyyyy = /^((([1-9]...$/
var ddmmyyyy = /^...$/
var mmyyyy = /^...$/
var yyyy = /^(17|18|19|20)\d{2}$/
if(!emptyString.test(theFo rm.ctl00$c tl00$cntrl ID_10724.v alue) && !dmmyyyy.test(theForm.ctl0 0$ctl00$cn trlID_1072 4.value) && !ddmmyyyy.test(theForm.ctl 00$ctl00$c ntrlID_107 24.value) && !mmyyyy.test(theForm.ctl00 $ctl00$cnt rlID_10724 .value) && !yyyy.test(theForm.ctl00$c tl00$cntrl ID_10724.v alue))
{
alert("Date appears invalid. Accepted formats include: \n\n d\/mm\/yyyy, dd\/mm\/yyyy, mm\/yyyy and yyyy");
//THIS IS WHERE I NEED TO FOCUS ON THE PROPER TAB
setTimeout( function() { $( '#tabs-0' ).focus() }, 500 ); //THIS DOESN'T WORK
theForm.ctl00$ctl00$cntrlI D_10724.fo cus(); //THIS WORKS IF I'M ALREADY IN THE ACTIVE TAB
}
else {
ClickOnce_ctl00_ctl00_btnS ubmit();
}
}
Who can help?
I'm trying to get there with this -- setTimeout( function() { $( '#tabs-0' ).focus() }, 500 );
but it doesn't work.
Here's how the .NET form begins...
<div class="divider"> </di
<script type="text/javascript" language="javascript"> $(document).ready(function
</tr>
...
<div id="tabs-0" class="tabs">
Here's the field I need to set focus to if the date format is incorrect:
...
<input name="ctl00$ctl00$cntrlID_
Here's the script I'm validating with, which includes the focus problem:
function validate() {
var theForm = document.forms['aspnetForm
if (!theForm) {
theForm = document.aspnetForm;
}
var emptyString = /^\s*$/ ;
var dmmyyyy = /^((([1-9]...$/
var ddmmyyyy = /^...$/
var mmyyyy = /^...$/
var yyyy = /^(17|18|19|20)\d{2}$/
if(!emptyString.test(theFo
{
alert("Date appears invalid. Accepted formats include: \n\n d\/mm\/yyyy, dd\/mm\/yyyy, mm\/yyyy and yyyy");
//THIS IS WHERE I NEED TO FOCUS ON THE PROPER TAB
setTimeout( function() { $( '#tabs-0' ).focus() }, 500 ); //THIS DOESN'T WORK
theForm.ctl00$ctl00$cntrlI
}
else {
ClickOnce_ctl00_ctl00_btnS
}
}
Who can help?
Slightly confusing - are you trying to move from one tab to another?
ASKER
Yes. There are three tabs. If I click "Submit" after finishing entry on the third tab, I want the validation function to switch focus to the first tab and to the problem field on the first tab that failed validation.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Cathal, for sending me in the right direction. Points to you.
Here's what worked for me:
$( "#tabbed" ).tabs( "option", "selected", 0 )
Cheers!
Here's what worked for me:
$( "#tabbed" ).tabs( "option", "selected", 0 )
Cheers!
ASKER
The answer wasn't exactly what I needed, but it gave me enough information that I could quickly track down the syntax that worked in my situation.
:o)
I should've checked the syntax but running to the pub!
I should've checked the syntax but running to the pub!