How to set default focus to the submit button in a popup window

please help me somebody ,,

I will write the code to get a popup using the following code.

<div id="EMAIL_CONFIRMATION_PENDING" class="popupContact" style="z-index:10003;"> <div class="popup_textarea"> <h3><h:outputLabel value="#{labelMsgs.emailPendingLabel}"/></h3> <div class="VerifyEmailText"> <h:outputLabel value="#{labelMsgs.clickToSendEmail}"/> <span class="FontItalic"><h:outputLabel value="#{headerBean.emailAddress}."/></span> <br /><br /> </div> <div class="SuspendedBoxMsg"> <h:outputLabel value="#{labelMsgs.accountSuspend}"/><br /> <h3><h:outputLabel value="#{sessionScope.DASHBOARD_EMAIL_EXP_TIME}"/></h3> <h:outputLabel value="#{labelMsgs.unlessYouVerify}"/> <br /> </div> <div> <span class="FontWeight"> <h:outputLabel value="#{labelMsgs.spamMailFolder}"/> </span> <a4j:commandLink id="resendLink" styleClass="violet_color_link" value="#{labelMsgs.regSuccSendMail}" onclick="javascript:resendLink(); this.onclick=null;" action="#{headerBean.resendEmail}" /> </div> <div class="OkButton"> <div class="button_input"> <a4j:commandButton id="emailConfm" styleClass="image_button" value="#{labelMsgs.okButton}" action="#{accntDashboardBean.popupRefresh}" reRender="frmAccountDashboardMenu:POPUP_PANEL" oncomplete="disablePopup1('EMAIL_CONFIRMATION_PENDING', 'backgroundPopup');popupCall('#{sessionScope.toShowPopupOf}');"/> </div> </div> </div> </div> 

in this am, using the id div to populate the popup, for example, I wrote different popup code with different identifiers. for this, I write code in the window.onload function to get a popup window, so I need to set the default focus to the submit button, which I mentioned in the code above.

+4
source share
2 answers

You can set focus on the submit button using javascript or jQuery:

JavaScript:

 document.getElementById('emailConfm').focus(); 

jQuery :

 $('#emailConfm').focus(); 
+9
source

you can use the following to set focus to button

 document.getElementById('emailConfm').focus(); 

But it may not work, to fix it, I did something like this

 setTimeout(function() { document.getElementById('emailConfm').focus(); },100); 
+5
source

All Articles