Vale, yo no suleo usar formularios con arrays pero el problema reside en como accedes al campo donde quieres insertar el valor.
Esto está bien:
Código Javascript
:
Ver originalfor (i = 0; i < document.frm.certificado.length; i++) {
if (certificado[i].checked) {
Pero aquí, estás accediendo por id:
Código Javascript
:
Ver originaldocument.getElementById("flag").value = txt;
La etiqueta id está pensada, como su nombre indica, para ser un identificador, un identificador único, por eso se espera que no se repita en el mismo documento, es decir, que si quieres que tu web esté bien diseñada no se deberían repetir id's.
Como se espera que sea único el primero que encuentra es el que coje y al que afecta.
Lo que no entiendo es porque no lo haces directamente en el bucle:
Código Javascript
:
Ver originalfunction marcar1(){
var txt = "";
var i;
for (i = 0; i < document.frm.certificado.length; i++) {
if (certificado[i].checked) {
//txt = document.frm.certificado[i].value;
flag[i].value = certificado[i].value;
}
}
//document.getElementById("flag").value = txt;
}
Por último si quieres que tu código sea más eficaz deberías ahorrarte ese bucle, como te digo yo no uso formularios con inputs de arrays pero podrías probar algo así:
Código PHP:
Ver original<form name="frm" id="frm">
<table class="table">
<tr>
<td>CERTIFICADO</td>
<td>ACCION</td>
</tr>
<?php
$index = 0;
foreach($rsCol as $rCol){
?>
<tr>
<td>
<input type="radio" name="certificado[]" id="certificado" value="1" onclick="marcar1(<?php echo $index; ?>)">
<input type="text" name="flag[]" id="flag">
</td>
<td>
<button type="submit" name="input_submit" value="Grabar">Grabar</button>
</td>
</tr>
<?php
$index++;
}
?>
</form>
Código Javascript
:
Ver originalfunction marcar1(index){
if (certificado[index].checked) {
//txt = document.frm.certificado[i].value;
flag[index].value = certificado[index].value;
}else{
//Al desmarcar...
}
//document.getElementById("flag").value = txt;
}
Algo así debería funcionar, si hay una forma mejor de pasarle el índice a la función de JS no la conozco porque como te he dicho suelo evitar este tipo de implementaciones.
Saludos!