FirePits
asked on
Change class onFocus
I have a simple table structure and would like to change the class of the row when the textbox within a cell is focused on.
<table>
<tr class="rowClass"><td>First Name:</td><td><input type="textbox" name="fName"></td></tr>
</table>
When fName is clicked on I want to change the <tr> class.
Any help is appreciated!
<table>
<tr class="rowClass"><td>First
</table>
When fName is clicked on I want to change the <tr> class.
Any help is appreciated!
Or you can even change back to the rowClass when you lost focus it
<script>
function fun(state) {
// onfocus
if ( state == 1 )
document.getElementById('m yRow').cla ssName = "AnotherRowClass";
// onblur
else if ( state == 2 )
document.getElementById('m yRow').cla ssName = "rowClass";
}
</script>
<table>
<tr id="myRow" class="rowClass">
<td>First Name:</td>
<td><input type="textbox" name="fName" onfocus="fun(1)" onblur="fun(2)"></td>
</tr>
</table>
<script>
function fun(state) {
// onfocus
if ( state == 1 )
document.getElementById('m
// onblur
else if ( state == 2 )
document.getElementById('m
}
</script>
<table>
<tr id="myRow" class="rowClass">
<td>First Name:</td>
<td><input type="textbox" name="fName" onfocus="fun(1)" onblur="fun(2)"></td>
</tr>
</table>
ASKER
I have multiple rows, so that won't work unless I can pass the row id to the function. With the research I've been doing, I think I need to somehow reference the parentNode property.
use parentNode and change the TR className
onfocus="this.parentNode.p arentNode. className= 'rowClassf ocus'"
onfocus="this.parentNode.p
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, thanks bubble!
<script>
function fun() {
document.getElementById('m
}
</script>
<table>
<tr id="myRow" class="rowClass">
<td>First Name:</td>
<td><input type="textbox" name="fName" onfocus="fun()"></td>
</tr>
</table>