The following code resides in my php file (cl.php):
<?php for( $i = 0; $i < count( $getClFormData->data ); $i++ ) :?>
<tr>
<input type='hidden' name='itemid[]' value='<?php echo $getClFormData->data[$i]['c_item_id'] ?>'>
<td><?php echo $getClFormData->data[$i]['item'] ?></td>
<td><?php echo $getClFormData->data[$i]['description'] ?></td>
<td><?php echo $getClFormData->data[$i]['norm'] ?></td>
<td>
<input type='radio' name='kforce_mont1_<?php echo $i ?>' value='1' class='bobtailradiook'>OK<br/>
<input type='radio' name='kforce_mont1_<?php echo $i ?>' value='0' class='bobtailradionok' alt='<?php echo $getClFormData->data[$i]['c_item_id'] ?>'>NOK
</td>
</tr>
<?php endfor;
where <input type='radio' name='kforce_mont1_<?php echo $i ?>' value='0' class='bobtailradionok' alt='<?php echo $getClFormData->data[$i]['c_item_id'] ?>'>NOK
is relevant to my question.
Further down cl.php, the following code:
if(isset($_POST['itemid'])){
<input type='hidden' class='test' value='<?php echo $_POST['itemid']; ?>'>
}
JS Code
$( document ).ready(function() {
$('.bobtailradionok').each(function() {
$( this ).click(function() {
//$("#errortable").show();
//alert($(this).attr('alt'));
$.ajax({
type: 'POST',
data: {itemid: $(this).attr('alt')},
url: "cl.php",
success:function(data){
alert($('.test').val());
console.log(data);
}
});
});
});
});
The jquery above returns 'undefined' in the alertbox, while I want it to return the itemid. Why is 'undefined' returned? Since, <input type='hidden' class='test' value='<?php echo $_POST['itemid']; ?>'>
is correctly returned as <input type='hidden' class='test' value='1'>
or <input type='hidden' class='test' value='2'>
depending on the box clicked, when I look in the console.log.