You need to do that way to access text field data:
array_id.push($('#textfield').val());
Because this refers to looped checkbox. And do you need to add this value in the loop each time?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hi i am using check box to get the value of that table...i need to send that array based on check box so here is my script...i am able to get that array in variable "array_id" but not able put the same in text box
<p1 type="text" id="textfield"></p1>
<script>
$(document).ready(function(){
$('#btn-mail').click(function(){
if(confirm("Are you sure you want to Proceed?"))
{
var array_id = [];
$(':checkbox:checked').each(function(i){
array_id[i] = $(this).val();
array_id.push($(this).find(('#textfield').val());
});
console.log(array_id);
// if(id.length === 0) //tell you if the array is empty
// {
// alert("Please Select atleast one checkbox");
// }
// else
// {
// $.ajax({
// url:'sendmail',
// method:'POST',
// data:{id:id},
// success:function()
// {
// for(var i=0; i<id.length; i++)
// {
// $('tr#'+id[i]+'').css('background-color', '#ccc');
// $('tr#'+id[i]+'').fadeOut('slow');
// }
// }
// });
// }
}
else
{
return false;
}
});
});
</script>
Please or to participate in this conversation.