I have some simple JavaScript functions:
function focus(id)
{
var e = document.getElementById(id);
if (e != null)
{
e.focus();
}
}
function show(id)
{
var e = document.getElementById(id);
if (e != null)
{
e.style.display = "inline";
}
}
I then have an html <a> tag with an onclick event:
<a title="Click This" onclick="focus('some_textbox'); show('some_panel');">Click This</a>
When I click on the "Click This" link, only the show() method executes. From some reason the focus method is never called. Any ideas why this is happening?
I’ve tried clearing my cache and have reversed the order of the focus() and show() methods. I’ve also verified that everything is spelled correctly.
Is it because focus() is already a function within JavaScript?
Edit: I tried renaming the function to focus2 and it seems to work now. Very strange. Anybody have any insight into why this happens?
Seems like you have a renaming issue here.
Just rename the function
focustofocusXor something different, this works for me in my test case.Remember to update the call to
focusin the href, tofocusX