1

I have a function like this:

function checksub7 (){
    var NetBusiness = $("#ConfigForm\\:NetBusiness").attr("value");
    var isShowRgHall = $("#ConfigForm\\:isShowRgHall")[0].checked;
    if(!NetBusiness == 'false' && isShowRgHall){
        var errorMsg = $("#errorMsg").attr("value");
        self.parent.$("#subframe").attr("src","../../webcontent/web/nocomponent.jsf?netbusinessmsg="+errorMsg+"&messagetype="+1);
        return false;
    }
    return true;

}

And an jsp file like this:

<h:form id="ConfigForm" onsubmit="waitForSubmit();">
    <table  class="configtable" cellpadding="0" cellspacing="0" >
        <tr>
            <td  class="configtd" style="padding-left:15px;;">

            <h:inputHidden id="NetBusiness" value="#{ConfigBean.hasNetBusiness}" />

            <div id="otherconfigdiv" class="configdiv">
                <table id="otherconfigtable"  class="configtable" cellpadding="0" cellspacing="0">

                    ...

                    <tr>
                        <td class="configlefttd ">&nbsp;</td>
                        <td class="configrighttd ">
                            <h:commandButton value="#{text['global.action.save']}" action="#{ConfigBean.update7}" styleClass="btn"  onclick="return checksub7();"/>
                                <span class="cmbtnspn10"></span>
                             <input type="button" value="${text['global.action.reset']}" class="btn" onclick="reset7();" />
                        </td>
                    </tr>
                </table>
            </div>

            </td>
        </tr>
    </table>
</h:form> 

I got an error at onclick="return checksub7();" say that Cannot return from outside a function or method. I have no idea about this and why this happen.

Can anyone help me to solve this?

Thank you.

gamo
  • 1,549
  • 7
  • 24
  • 36
  • 1
    `onclick` expects a function and not a value. `onclick=checksub7()` should be enough. – Rajesh Mar 15 '16 at 11:51
  • Is it a JS error in console, or a JSP error? – rrk Mar 15 '16 at 11:53
  • @RejithRKrishnan Error marker is in the jsp file. – gamo Mar 15 '16 at 11:59
  • @Rajesh You are right, but I'm not sure is there any difference. Let me google some. – gamo Mar 15 '16 at 12:01
  • 1
    You can try `function{return checksub7();}` which is same as `checksub7();`. Point is, return function can be used in side a function. – Rajesh Mar 15 '16 at 12:03
  • 1
    The significance of `return` in the `onclick` attribute is that once the function return `false`, then the default action of the button will be stopped. Just saying. – rrk Mar 15 '16 at 12:07
  • @RejithRKrishnan Could you tell more detail about this? – gamo Mar 15 '16 at 12:33
  • 1
    @user3422401: That is all basic html... http://stackoverflow.com/questions/7814949/javascript-onclick-return-functionality – Kukeltje Mar 15 '16 at 12:46

0 Answers0