简体   繁体   English

如何在JSP中的onClick(按钮)上调用Java Script函数?

[英]How to call Java Script function on onClick ( button ) in JSP?

I would like to trigger the js function onClick from button. 我想从按钮触发js函数onClick。 for some reason i am facing Function not defined. 由于某种原因,我正面临未定义的功能。

Need to call this in JSP 需要在JSP中调用它

// doUpdate function details
boolean doUpdate = request.getParameter("update")!=null;
String stateButton = request.getParameter("update");

if (doUpdate && catalogID != null && companyID != 0) {
    if(catalogManager!=null) {
        boolean success = catalogManager.updateStatus(new Integer(catalogID).intValue(),user, stateButton);
        if((stateButton.equals("Active")) && success) { 
    %>          
        <span class="TitleLevel01"><font color=green>Catalog is Activated.</font></span>
    <%
        }
        if((stateButton.equals("Active")) && !success) {
    %>
        <span class="TitleLevel01"><font color=red>Cannot activate subcatalog with Inactive parent.</font></span>
    <%      
        }
        if(!stateButton.equals("Active")) {
    %>                  
            <span class="TitleLevel01"><font color=green>Catalog is Deactivated.</font></span>
    <%      
            }
        }
    }

from this Form (looks like this) 从此表单(看起来像这样)

 <form name="maintain_catalog_frm" id="maintain_catalog_frm" >
    <input type=hidden name="PID" value="">
    <input type="submit" name="update" value="Inactive" onClick="return doUpdate(document.maintain_catalog_frm);" >
    </form>

It means that the javascript is still not loaded. 这意味着仍未加载javascript。

It could be your cache, or you could be having some wrong path to the JS file. 它可能是您的缓存,或者您的JS文件路径错误。 What is the path to the JS file , and has it been downloaded? JS文件的路径是什么,并且已下载?

Do you have js in the jsp or have you included js file in your jsp? 您在jsp中包含js或在jsp中包含js文件?

Include your script in in your jsp. 在jsp中包括您的脚本。

It looks like you have a jsp not js to execute here. 看来您要在这里执行而不是js的jsp。

Is companyid and catalogue initialised properly? 公司ID和目录是否正确初始化?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM