Reputation: 1299
VB script statement ,
Set oHighlightedRow = document.all("SearchRow" & nHighlightedRow)
oHighlightedRow.cells(0).focus()
These two statments need to be converted to javascript.anyone can help me to find a solution? Thanx
My converted code was,
var oHighlightedRow = $("#SearchRow" + nHighlightedRow);
oHighlightedRow.cells[0].focus();
Is this correct ?
Upvotes: 2
Views: 26405
Reputation: 22619
You can do this simply with the help of jQuery library with simple lines
$('selector').focus();
// $('selector') --> could be $('#tableId td')
For more information please check http://api.jquery.com/category/selectors/
Upvotes: 0
Reputation: 9541
You cannot focus table cells on all browsers. Here is what the jQuery documentation says:
The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property. An element can gain focus via keyboard commands, such as the Tab key, or by mouse clicks on the element.
To make sure this works with all browsers you can implement some CSS class and add event listeners for mouse keys. Then just add/remove the css classes from table cells.
in order to focus an element with id="target"
use this
$('#target').focus();
Upvotes: 2
Reputation: 150010
OK:
var oHighlightedRow = document.all("SearchRow" + nHighlightedRow);
oHighlightedRow.cells[0].focus();
Or, better (assuming the row has an id of "SearchRow" + nHighlightedRow
):
var oHighlightedRow = document.getElementById("SearchRow" + nHighlightedRow);
oHighlightedRow.cells[0].focus();
Or, jQuery (again assuming the row has an id of "SearchRow" + nHighlightedRow
):
$("#SearchRow" + nHighlightedRow + " td:first").focus();
Upvotes: 5