取消后继续提交确认()

时间:2016-06-03 21:16:24

标签: javascript asp-classic

我正在处理从表中删除记录的代码,确认操作的按钮指向以下js。

<script type = "text/JavaScript"> 
function pregunta(){ 
if (confirm('¿Estas seguro de realizar esta acción')){ 
   document.myForm.submit(); 
} 
} 
</script>

问题是当你点击按钮取消时,表格仍然是提交

 <form role="form" method="get" action="index.asp" id="myForm"    name="myForm">
 <div class="container">
    <div class="well well-sm">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-11"><h2>Aprobaciones Subcontrato</h2></div>
          <div class="col-md-1"><a href="index.asp"><img src="images/house.png" style="width:42px;height:42px;border:0"></a></div>
        </div>          
        <p>En el siguiente recuadro ingrese el número del subcontrato a revisar y el numero de ticket.</p>
        <div class="form-group">
          <div class="row">
            <div class="col-md-6">
              <label for="txtSubcontrato">Subcontrato:</label>
              <input type="string" class="form-control" id="txtSubContrato" placeholder="Ingrese Subcontrato" name="txtSubContrato" value="<%= txtSubContrato %>" min="1" required>
            </div>
            <div class="col-md-4">
              <label for="ticket">Ticket:</label> 
              <input type="number" class="form-control" id="iTicket" placeholder="Ingrese Ticket" name="iTicket" value="<%= iTicket %>" min="1" required>
            </div>
          </div>
        </div>
        <button type="submit" form="myForm" class="btn btn-default" name="btnBuscar" id="btnBuscar">Buscar</button>
      </div>
    </div>
  </div>         
  <%     
    <!-- Eliminar y Respaldar--> 
    If (Request.QueryString("btnEliminar") = "Respaldar y Eliminar") Then
    Response.Write ("delete")
<!-- botonera -->
      Response.Write       "<div class='col-md-6'>"
      If iExiste = 1 Then
      If (ap=1 and asu=1 and aso=1 and Cstr(rsSub("status_sub"))="A" and Cstr(rsMonto("montoavanzado"))=0) Then
        Response.Write       "<button class='btn btn-default' onclick='pregunta()' id='btnEliminar' value='Respaldar y Eliminar' name='btnEliminar' readonly/> 111" 
      ElseIf (ap=1 and asu = 1 and aso = 0 and Cstr(rsSub("status_sub"))="I" and Cstr(rsMonto("montoavanzado"))=0) Then 
        Response.Write       "<button class='btn btn-default' onclick='pregunta()' id='btnEliminar' value='Respaldar y Eliminar' name='btnEliminar' readonly/> 110"
      ElseIf (ap=1 and asu = 0 and aso = 0 and Cstr(rsSub("status_sub"))="I" and Cstr(rsMonto("montoavanzado"))=0) Then  
        Response.Write       "<button class='btn btn-default' onclick='pregunta()' id='btnEliminar' value='Respaldar y Eliminar' name='btnEliminar' readonly/> 100"
      ElseIf (ap=0 and asu = 0 and aso = 0 and Cstr(rsSub("status_sub"))="I" and Cstr(rsMonto("montoavanzado"))=0) Then 
        Response.Write       "<button class='btn btn-default' onclick='pregunta()' id='btnEliminar' value='Respaldar y Eliminar' name='btnEliminar' readonly/>000"
      Else 
        Response.Write       "<button type='button' class='btn btn-default disabled'> Respaldar y Eliminar</button>"
      End If 
      Else Response.Write       "<button type='button' class='btn btn-default disabled'> Respaldar y Eliminar</button>"
      End If
      Response.Write       "</div>"  
      Response.Write     "</div>"
      Response.Write   "</div>"
      Response.Write "</div>"

正如您可以看到该页面,首先请求一个数字来搜索数据库,使用表单,然后加载数据并提供删除选项

1 个答案:

答案 0 :(得分:1)

您应该在表单的onsubmit事件上使用return false以阻止提交

你可以像

那样做

onsubmit="return callIReallySubmit();"

function callIReallySubmit() { do your logic to test if you can submit.. return canSubmitOrNot; }

勘误表: 问题实际上是按钮上的type="submit",将其更改为type='button'