ginerjm Posted April 13, 2011 Share Posted April 13, 2011 Now that I've discovered that the HTML TABLE element doesn't support a name attribute or a tabindex one, and neither do the TR or TD elements I'm wondering if JS can come to my rescue. I'm new to it and don't find anything so far on this feature I've used simple xx.xx.focus statements in onclick events or onload events, but since I can't set a name attribute on a table or td element, I can't do that here. Any possibilities here? Quote Link to comment https://forums.phpfreaks.com/topic/233632-can-js-set-focus-on-a-table-element-when-a-page-loads/ Share on other sites More sharing options...
nogray Posted April 13, 2011 Share Posted April 13, 2011 tables, tr, td can't have focus since the user doens't interact with them directly. Depending on what are you trying to do with the focus event, there is another approach. You can add an anchor tag inside your td and once that anchor tag receive focus, you would simulate a focus on the td visually. Here is a quick sample. <input type="text" value="tab out of here" /> <table id="my_table" style="cursor:pointer;" onclick="do_focus(); do_click(); document.getElementById('my_anchor').focus();"> <tr> <td> <a href="#" id="my_anchor" onclick="do_click(); return false;" onfocus="do_focus();" onblur="do_blur();"></a> This is some text </td> </tr> </table> <input type="text" value="tab out of here" /> <script type="text/javascript"> function do_click(){ alert('clicked'); }; function do_focus(){ document.getElementById('my_table').style.background = "#336699"; document.getElementById('my_table').style.color = "#ffffff"; document.getElementById('my_table').style.border = "dotted 1px #000000"; }; function do_blur(){ document.getElementById('my_table').style.background = "#ffffff"; document.getElementById('my_table').style.color = "#000000"; document.getElementById('my_table').style.border = "0px"; }; </script> Quote Link to comment https://forums.phpfreaks.com/topic/233632-can-js-set-focus-on-a-table-element-when-a-page-loads/#findComment-1201239 Share on other sites More sharing options...
ginerjm Posted April 13, 2011 Author Share Posted April 13, 2011 ok - I see the concept of burying an anchor in my td. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/233632-can-js-set-focus-on-a-table-element-when-a-page-loads/#findComment-1201249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.