<p>If you have a JSF <code>&lt;h:commandLink&gt;</code> (which uses the <code>onclick</code> event of an <code>&lt;a&gt;</code> to submit the current form), how do you execute JavaScript (such as asking for delete confirmation) prior to the action being performed?</p>

```
```
<h:commandLink id="myCommandLink" action="#{myPageCode.doDelete}">
    <h:outputText value="#{msgs.deleteText}" />
</h:commandLink>
<script type="text/javascript">
if (document.getElementById) {
    var commandLink = document.getElementById('<c:out value="${myPageCode.myCommandLinkClientId}" />');
    if (commandLink && commandLink.onclick) {
        var commandLinkOnclick = commandLink.onclick;
        commandLink.onclick = function() {
            var result = confirm('Do you really want to <c:out value="${msgs.deleteText}" />?');
            if (result) {
                return commandLinkOnclick();
            }
            return false;
        }
    }
}
</script>
```
```
Other Javascript actions (like validating form input etc) could be performed by replacing the call to
```
confirm()
```
with a call to another function.