i'm trying to use the following code to insert test into a field without id
$(document).ready(function(){
$("#insert").click(function(){
$("#gfield_list_cell gfield_list_356_cell2").val("TEST");
});
});
<td class="gfield_list_cell gfield_list_356_cell2" data-label="FIRST"><input type="text" name="input_356[]" value="" tabindex="14"></td>
<p><input id="insert" name="test" type="button" value="test" /></p>
</div>
your selector is ID selector, not a CLASS selector
$(document).ready(function(){
$("#insert").click(function(){
$(".gfield_list_cell gfield_list_356_cell2").val("TEST");
});
});
should work.
or if you want to change the value of the INPUT TYPE="text" you should do:
$(document).ready(function(){
$("#insert").click(function(){
$(".gfield_list_cell gfield_list_356_cell2").children().val("TEST");
});
});
$(document).ready(function(){
$("#insert").click(function(){
$("#testing").val("TEST");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<td class="gfield_list_cell" data-label="FIRST"><input id="testing" type="text" name="input_356[]" value="" tabindex="14"></td>
<p><input id="insert" name="test" type="button" value="test" /></p>
</div>
You can achieve that by specifying the classes of your td
tag and the input field inside it, to be more specific (considering you do not have any other input inside the td).
$(document).ready(function() {
$("#insert").click(function() {
$(".gfield_list_cell.gfield_list_356_cell2").children("input").val("TEST");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="gfield_list_cell gfield_list_356_cell2" data-label="FIRST"><input type="text" name="input_356[]" value="" tabindex="14"></td>
</tr>
<table>
<p><input id="insert" name="test" type="button" value="test" /></p>
I hope this helps you.
Good luck.
</div>