在经典asp中单击按钮时调用多个函数

时间:2013-09-26 12:19:45

标签: javascript asp-classic

如何在确认删除按钮上调用多个功能?

以下是我需要调用的函数:

    function ifnull() {
                if (selected_devices_area = "") {
                    window.alert("Please select devices!");
                }
            }

    function submitForm() {

                if (confirm("Do you really want to delete these devices?")) {
                    //document.location.href = '/site/service/device/DeleteMultipleDevices.asp?siteId=<%=iSiteId%>&serviceId=<%=iServiceId%>';

                    document.device.submit();
                    window.alert('Devices successfully deleted.');

                }

按钮的HTML:

        <tr>    
            <td><a href="/site/service/serviceinfo_main.asp?siteId=<%=iSiteId%> &crType=Delete Multiple Devices&addCr=yes&crId=<%=iCrId %>"class="btnLink">&laquo; Back</a></td>
            <td class="tdRight"><a href="javascript:ifnull();javascript:submitForm();" class="btnLink">Confirm Deletion &raquo;</a></td>
        </tr>
    </table>

我正在调用这样的函数,但它不起作用。

1 个答案:

答案 0 :(得分:2)

您不需要使用“javascript:”前缀两次。而不是

<a href="javascript:ifnull();javascript:submitForm();" class="btnLink">

待办事项

<a href="javascript:ifnull();submitForm();" class="btnLink">

但更重要的是,如果我理解正确ifnull()未通过 - 您不想提交表格。如果是这样,请将ifnull()功能更改为:

function ifnull() {
   if (selected_devices_area = "") {
       window.alert("Please select devices!");
       return true
   } else {
       return false
   }
}

然后您可以将submitForm()功能更改为

function submitForm() {
   if (!ifnull() && confirm("Do you really want to delete these devices?")) {
        document.device.submit();
        // You should generate "alert('Devices successfully deleted.');" from server side
        // since as of now you don't know that is really happend
}

并将您的电话改为

<a href="submitForm();" class="btnLink">

这种方式更简洁。