Wen Ji
Wen Ji

Reputation: 55

How do I focus on a javascript radio button or any other items on specific jquery tabs?

I have javascript validation that validates items such as textboxes, radio buttons etc. How do I use focus() on the text box or other item located in a specific tab governed by tags?

Sample of the javascript code:

if (theForm.radbtnProg.checked && theForm.ddlProg.selectedIndex == 0) {
    alert("Please select Institution Name from the list.");
    theForm.ddlProg.focus();
}

Above example theForm.radbtnProg.checked and theForm.ddlProg.selectedIndex are the radio button and drop down list that I want to validate. How do I refer to them according to specific tabs?

$('#tabs').tabs(theForm.radbtnProg.checked)?

Edited: Answered by @nnnnnn and I modified the code:

if (theForm.radProg.checked && theForm.ddlProg.selectedIndex == 0) {
    alert("Please select Program Name from the list.");
    $('#tabs').tabs("select", 0);
    $("#ddlProg").focus();
    return false;
}

Upvotes: 1

Views: 9981

Answers (1)

Adam Rackis
Adam Rackis

Reputation: 83366

Just select what you want to focus, and call jQuery's focus

$(theForm.ddlProg).focus();

And of course you could select this select any other way:

$("select[name='ddlProg']").focus();

Upvotes: 1

Related Questions