Pass text from a textbox via onclick parameter

0

I need to pass as parameter the content that is in textbox , in onclick of a button. How can I do this?

This is the Html code:

<div id="popup">
<table width="300" height="160">
    <tr>

        <td colspan="3" height="20" style="text-align:right"><input type="submit" value="Fechar X" id="FecharModal" onclick="fecharDialog()" /></a></td>
    </tr>
    <tr>
        <td colspan="3" style="text-align: center; font-weight: bold; font-size:15px"><div id="texto"><p></p></div></td>
    </tr>
    <tr>
        <td height="30" style="text-align:center"><input type="submit" value="Sim" id="ValidaSim" onclick="ValidaSim()" /></td>
        <td height="30" style="text-align:center" colspan="2"><input type="submit" value="Não" id="ValidaNao" onclick="ValidaNao()" /></td>
    </tr>
    <tr>
        <td height="30" style="text-align:center; display:none"><input type="text" id="txtValid" /></td>
        <td height="30" style="text-align: center; display: none"><input type="text" id="txtDrop" /></td>
        <td height="30" style="text-align: center; display: none"><input type="text" id="txtMatricula" /></td>
    </tr>
</table>

In the onclick of the input Valida I need to pass the text that is in textbox txtValid, as a parameter. In the onclick of the input valid, I do not need to pass the text of all textbox down as parameters.

<td height="30" style="text-align:center; display:none"><input type="text" id="txtValid" /></td>
<td height="30" style="text-align: center; display: none"><input type="text" id="txtDrop" /></td>
<td height="30" style="text-align: center; display: none"><input type="text" id="txtMatricula" /></td>
    
asked by anonymous 04.02.2016 / 17:59

1 answer

1

Here's a very simplistic way to do what you want

var baseUri = 'http://urldoseusite.com/?'

function ValidaSim() {

  var uri = baseUri + "parametro1=" + $('#txtValid').val();
  alert(uri); // Remover esta linha depois quando implementar em seu projeto.
  window.location = uri;

}

function ValidaNao() {

  var uri = baseUri +
    "parametro1=" + $('#txtValid').val() +
    "&parametro2=" + $('#txtDrop').val() +
    "&parametro3=" + $('#txtMatricula').val();
  alert(uri); // Remover esta linha depois quando implementar em seu projeto.
  window.location = uri;

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="popup">
  <table width="300" height="160">
    <tr>

      <td colspan="3" height="20" style="text-align:right">
        <input type="submit" value="Fechar X" id="FecharModal" onclick="fecharDialog()" />
      </td>
    </tr>
    <tr>
      <td colspan="3" style="text-align: center; font-weight: bold; font-size:15px">
        <div id="texto">
          <p></p>
        </div>
      </td>
    </tr>
    <tr>
      <td height="30" style="text-align:center">
        <input type="submit" value="Sim" id="ValidaSim" onclick="ValidaSim()" />
      </td>
      <td height="30" style="text-align:center" colspan="2">
        <input type="submit" value="Não" id="ValidaNao" onclick="ValidaNao()" />
      </td>
    </tr>
    <tr>
      <td height="30" style="text-align:center;">
        <input type="text" id="txtValid" value="valor da txt valid" />
      </td>
      <td height="30" style="text-align: center;">
        <input type="text" id="txtDrop" value="valor da txt drop" />
      </td>
      <td height="30" style="text-align: center;">
        <input type="text" id="txtMatricula" value="valor da txt matricula" />
      </td>
    </tr>
  </table>
  <div>
    
04.02.2016 / 18:25