How to take the value of an input within a <td> in jquery

Asked

Viewed 3,874 times

1

Ola, I have the following table in html

<table style="display:none;" id="tableTime">  
        <tr>
            <td class="hora">08:00</td>
            <td class="eventoAgenda" id="0800"></td>
            <td class="idEvento" id="id0800"></td>
            <td class="statusVerde"> <input name="status" type="checkbox" ></input> </td>
        </tr> 

How do I get the <input> that is inside the <td class="statusVerde> in jquery??

I tried something similar to this:

$('#tableTime tr #statusVerde input #status')

but it obviously didn’t work out

  • $("#tableTime input[name='status'") to access the input name.

  • and if the table is dynamic? type exist some imput with the same name? how can I take the value of each one? in javascrip

2 answers

3


Add id="status" at the input. See working:

$(document).ready(function() {
  var a = $('#status').val();
  alert(a);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table style="display:none;" id="tableTime">
  <tr>
    <td class="hora">08:00</td>
    <td class="eventoAgenda" id="0800"></td>
    <td class="idEvento" id="id0800"></td>
    <td class="statusVerde">
      <input name="status" id="status" type="checkbox" value="teste"></input>
    </td>
  </tr>

Or by the attribute name:

$(document).ready(function() {
  var a = $('input[name="status"]').val();
  alert(a);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<table style="display:none;" id="tableTime">
  <tr>
    <td class="hora">08:00</td>
    <td class="eventoAgenda" id="0800"></td>
    <td class="idEvento" id="id0800"></td>
    <td class="statusVerde">
      <input name="status" type="checkbox" value="teste"></input>
    </td>
  </tr>

Reference:

How to set value of input text using jQuery

1

You need to initialize an attribute to your input for example <input name="status" id="statusAqui" type="checkbox"> after this select it with jQuery $('#statusAqui').

Browser other questions tagged

You are not signed in. Login or sign up in order to post.