views:

243

answers:

1

How do I use Javascript to "click" on a CommandButton?

I tried the following but it doesnt work:

<ice:panelTab id="searchResultsTab" label="Search Results" onclick="document.getElementById('form:searchTabs:0:refreshButton').click();">

Thanks.

+1  A: 

Either the element ID is wrong, or the ice:panelTab itself is doing something during onclick as well which has overriden your onclick, or the HTML rendering went bogus (this can happen in one very specific situation) and the onclick attribute has never been rendered to the response.

To fix the first, doublecheck the page source. To fix the second, check the page source if that is indeed the case and then add a return false; to end of the onclick. To fix the third, you'll first need to confirm that the onclick is indeed not there in the HTML output and then tell more about JSF API and impl versions.

All with all, the answer is in the generated HTML output. It's also the running context of Javascript.

BalusC
Strange...I've double checked the ID but it doesnt seem to work...If I move the commandButton out of the panelTabSet and change the Id to form:refreshButton it does work...is this some AJAX issue? Cant see how to access it.
DD
Sorry, since I don't do IceFaces, I can't tell from head how it is supposed to behave and generate HTML. Just check and debug the generated HTML/JS source. [Firebug](http://getfirebug.com) is very helpful here.
BalusC