Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Stop function through JavaScript

I have this js function :

function neki() {
  if ( $("input[id*='txtIDCriteria']").val() == ''
    && $("input[id*='chkID']").is(':checked')
  ) {
    alert('Value is required.');
  }
}

And this asp code:

<table border="0" cellpadding="1" cellspacing="0"
  style="width: 100%" class="DataTable" id="check_all"
>
  <tr>
    <td>
      <asp:CheckBox CssClass="formdata100" ID="chkID" runat="server"> 
      </asp:CheckBox>
    </td>
    <td>
      <asp:Label CssClass="formdata100" ID="lblID" runat="server">
        Maintenance ID
      </asp:Label>
    </td>
    <td>
      <asp:TextBox CssClass="formdata100" ID="txtIDCriteria"
        runat="server" MaxLength="6"
        onkeyup="return validate_int(event,this);"
      >
      </asp:TextBox>
    </td>
  </tr>
  <tr>
    <td colspan="5">
      <asp:Button Text="search" ID="search" OnClick="search_Click"
        runat="server" style="float:right" onClientClick="neki()"
      />
    </td>
  </tr>

I want this OnClick="search_Click" to stop when this function neki() is executed ie when it is true.

How to solve it through JavaScript?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, you can do this. The way this works?

If the onclient click function returns true, then the server side code/event runs.

If the onclient click function returns false, then the server side code/event does NOT run. So you can do this:

   <asp:Button Text="search" ID="search" OnClick="search_Click"
    runat="server" style="float:right" onClientClick="return neki();"

And now your JS code can be this:

function neki() {
    if ( $("input[id*='txtIDCriteria']").val() == ''
        && $("input*[id*='chkID']").is(':checked'))
    {
    alert('Value is required.');
    return true;
    }
    return false;
}

While this will work for above, if you use a jQuery.UI dialog, the code does not wait, but there is a simple work around for even jQuery.UI dialog that respond to say a yes/no answer, and you can still conditional run the server side button code.

edit: opps - I have this backwards.

the code should be like this:

function neki() {
    if ( $("input[id*='txtIDCriteria']").val() == ''
        && $("input*[id*='chkID']").is(':checked'))
    {
    alert('Value is required.');
    return false;  <--- return false to NOT run button click
    }
    return true;   <--- return true - this will allow button click to run
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda