Foros del Web » Programando para Internet » Javascript »

[SOLUCIONADO] seleccion de radio button

Estas en el tema de seleccion de radio button en el foro de Javascript en Foros del Web. buenas, estoy haciendo un proyecto en el cual me trae una serie de registros y me los muestra en una tabla en el cual tengo ...
  #1 (permalink)  
Antiguo 14/01/2015, 07:49
 
Fecha de Ingreso: octubre-2013
Mensajes: 24
Antigüedad: 10 años, 5 meses
Puntos: 0
seleccion de radio button

buenas, estoy haciendo un proyecto en el cual me trae una serie de registros y me los muestra en una tabla en el cual tengo que mostrar en uno de los campos de la tabla la fecha actual en que estamos al seleccionar el radio button correspondiente a la fila, pero que sucede: cuando selecciono cualquier radio button en vez de colocarse la fecha actual en el campo correspondiente de la fila seleccionada, no lo hace se coloca solo en la primera fila, se que debo chequear en q fila estoy y asignarle un id al campo donde quiero mostrar la fecha pero no se como hacerlo, seria de mucha molestia que me ayuden? aca esta mi codigo.

Código PHP:
<script language="javascript">
var 
= new Date();

function 
fAgrega(value)
{


document.getElementById("fp").innerHTML f.getDate() + "/" f.getMonth() + "/" f.getFullYear();
alert(value);

}
</script> 
Código PHP:
<div style="padding-left: 10px;"
         <
label class="colorG"></label
         <
fieldset class="campofieldsetM">
                <
legend>Administrador de Publicación de Cargos</legend>    
        <
form action="" method="post" enctype="multipart/form-data" target="_self" id="theForm" name="theForm">
        
        <
label >Lista de Vacantes</label>
        <
table width="1008"  cellpadding="0" border="1" bordercolordark="#CCCCCC" cellspacing="0" style="text-align:center">
            <
thead bgcolor="#999999">
                <
tr>
                <
th width="54">ITEM</th>
                <
th width="285">Gerencia</th>
                <
th width="227">Vacante</th>
                <
th width="81">Status</th>
                <
th width="159">Fecha de Publicación</th>
                <
th width="124">Fecha de Cierre</th>
                <
th width="76">Gestionar</th>
                </
tr>
            </
thead>
                        <
tbody>
                   <
tr>
                <
td width="54"><span title="ITEM"><label name="item" id="item" value="1">1</label></span></td>
                <
td width="285"><span title="Gerencia" style="font-size:13px">GERENCIA DE ADMINISTRACIÓN</span></td>
                <
td width="227"><span title="Cargo" style="font-size:13px">ANALISTA DE FACTURACIÓN</span></td>
                <
td width="81"><span title="Status"><label name="status" id="status" value="0"></label></span></td>
                <
td width="159"><span title="fp" id="fp"></span></td>
                <
td width="124"><span title="fc" id="fc"></span></td>
                <
td width="76" align="center"><span title="Gestionar"><input  name="gestionar" id="gestionar" type="radio" value="1" onChange="fAgrega(this.value);" onClick="nv.disabled = false; pv.disabled = false"/></span></td>
                </
tr>
            </
tbody>
                    <
tbody>
                   <
tr>
                <
td width="54"><span title="ITEM"><label name="item" id="item" value="2">2</label></span></td>
                <
td width="285"><span title="Gerencia" style="font-size:13px">GERENCIA DE ADMINISTRACIÓN</span></td>
                <
td width="227"><span title="Cargo" style="font-size:13px">EJECUTIVA DE APS</span></td>
                <
td width="81"><span title="Status"><label name="status" id="status" value="0"></label></span></td>
                <
td width="159"><span title="fp" id="fp"></span></td>
                <
td width="124"><span title="fc" id="fc"></span></td>
                <
td width="76" align="center"><span title="Gestionar"><input  name="gestionar" id="gestionar" type="radio" value="2" onChange="fAgrega(this.value);" onClick="nv.disabled = false; pv.disabled = false"/></span></td>
                </
tr>
            </
tbody>
                </
table><br>

        
</
form>


</
fieldset>

</
div
el que me pueda ayudar muchas gracias de antemano! :/
  #2 (permalink)  
Antiguo 14/01/2015, 19:34
 
Fecha de Ingreso: enero-2015
Mensajes: 43
Antigüedad: 9 años, 3 meses
Puntos: 3
Respuesta: seleccion de radio button

estas repitiendo los ids fp, fc y gestionar, la definicion de la funcion segun el navegador te va a levantar o el primer elemento con ese id o el ultimo.

primero, veriifica que cada elemento si necesita un id, este sea unico en el DOM
2, lo mas facil es modificar el el metodo fAgrega
Código HTML:
function fAgrega(value, el_target)
{


el_target.innerHTML = f.getDate() + "/" + f.getMonth() + 1 + "/" + f.getFullYear();
alert(value);

}
y en el html
Código PHP:
<div style="padding-left: 10px;"
         <
label class="colorG"></label
         <
fieldset class="campofieldsetM">
                <
legend>Administrador de Publicación de Cargos</legend>    
        <
form action="" method="post" enctype="multipart/form-data" target="_self" id="theForm" name="theForm">
        
        <
label >Lista de Vacantes</label>
        <
table width="1008"  cellpadding="0" border="1" bordercolordark="#CCCCCC" cellspacing="0" style="text-align:center">
            <
thead bgcolor="#999999">
                <
tr>
                <
th width="54">ITEM</th>
                <
th width="285">Gerencia</th>
                <
th width="227">Vacante</th>
                <
th width="81">Status</th>
                <
th width="159">Fecha de Publicación</th>
                <
th width="124">Fecha de Cierre</th>
                <
th width="76">Gestionar</th>
                </
tr>
            </
thead>
                        <
tbody>
                   <
tr>
                <
td width="54"><span title="ITEM"><label name="item" id="item" value="1">1</label></span></td>
                <
td width="285"><span title="Gerencia" style="font-size:13px">GERENCIA DE ADMINISTRACIÓN</span></td>
                <
td width="227"><span title="Cargo" style="font-size:13px">ANALISTA DE FACTURACIÓN</span></td>
                <
td width="81"><span title="Status"><label name="status" id="status" value="0"></label></span></td>
                <
td width="159"><span title="fp" id="fp1"></span></td>
                <
td width="124"><span title="fc" id="fc1"></span></td>
                <
td width="76" align="center"><span title="Gestionar"><input  name="gestionar" id="gestionar1" type="radio" value="1" onChange="fAgrega(this.value, document.getElementById('fp1'));" onClick="nv.disabled = false; pv.disabled = false"/></span></td>
                </
tr>
            </
tbody>
                    <
tbody>
                   <
tr>
                <
td width="54"><span title="ITEM"><label name="item" id="item" value="2">2</label></span></td>
                <
td width="285"><span title="Gerencia" style="font-size:13px">GERENCIA DE ADMINISTRACIÓN</span></td>
                <
td width="227"><span title="Cargo" style="font-size:13px">EJECUTIVA DE APS</span></td>
                <
td width="81"><span title="Status"><label name="status" id="status" value="0"></label></span></td>
                <
td width="159"><span title="fp" id="fp2"></span></td>
                <
td width="124"><span title="fc" id="fc2"></span></td>
                <
td width="76" align="center"><span title="Gestionar"><input  name="gestionar" id="gestionar2" type="radio" value="2" onChange="fAgrega(this.value,, document.getElementById('fp2'));" onClick="nv.disabled = false; pv.disabled = false"/></span></td>
                </
tr>
            </
tbody>
                </
table><br>

        
</
form>


</
fieldset>

</
div
  #3 (permalink)  
Antiguo 16/01/2015, 10:36
 
Fecha de Ingreso: octubre-2013
Mensajes: 24
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: seleccion de radio button

muchas gracias amigo me funciono.

ahora si puedes ayudarme con otra cosita: cuando seleccione el radio button 1 me marca la fecha en el campo de la fila 1 pero si paso el radio button al 2 me deja puesta la fecha en el campo de la fila 1 y me la pone en el 2 como hago para que cuando no este seleccionado el radio button 1 no me deje el campo de la fila uno con la fecha? ;(

por favor, y gracias de antemano amigo
  #4 (permalink)  
Antiguo 16/01/2015, 10:56
Avatar de GeekGirl  
Fecha de Ingreso: julio-2014
Mensajes: 423
Antigüedad: 9 años, 9 meses
Puntos: 44
Respuesta: seleccion de radio button

Podrías hacer algo así:

Código Javascript:
Ver original
  1. function fAgrega(value, el_target)
  2. {
  3.     var idVal = (value == 2) ? 1 : 2;
  4.     document.getElementById("fp" + idVal).innerHTML = "";
  5.  
  6.     el_target.innerHTML = f.getDate() + "/" + f.getMonth() + 1 + "/" + f.getFullYear();
  7. }

Saludos :)
  #5 (permalink)  
Antiguo 16/01/2015, 14:16
 
Fecha de Ingreso: octubre-2013
Mensajes: 24
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: seleccion de radio button

si tengo "n" cantidad de registros en la tabla como haria en ese caso? colocandole un ciclo for? o como podria hacer? :S
y si lo uso asi como me dices se me queda marcado la fila 2 y deberia quedar marcado el que este chequeado ;s

por favor ayuda :/

Última edición por preto960; 16/01/2015 a las 14:43
  #6 (permalink)  
Antiguo 20/01/2015, 08:42
Avatar de GeekGirl  
Fecha de Ingreso: julio-2014
Mensajes: 423
Antigüedad: 9 años, 9 meses
Puntos: 44
Respuesta: seleccion de radio button

Y bueno pero pon un poco de tu parte, no pidas el código servido...

Podés por ejemplo darle una clase a todos los spans donde se guarda la fecha de publicación:

Código HTML:
<td width="159"><span title="fp" id="fp2" class="fechaPublicacion"></span></td> 
Y luego simplemente usar esa clase para borrar el valor de todos antes de insertar uno nuevo:

Código Javascript:
Ver original
  1. var f = new Date();
  2.  
  3. function fAgrega(value, el_target)
  4. {
  5.     var allSpans = document.getElementsByTagName('span');
  6.  
  7.     for (var a = 0; a < allSpans.length; a++) {
  8.       if (allSpans[a].className == 'fechaPublicacion') {
  9.         allSpans[a].innerHTML = "";
  10.       }
  11.     }
  12.  
  13.      el_target.innerHTML = f.getDate() + "/" + f.getMonth() + 1 + "/" + f.getFullYear();
  14. }
  #7 (permalink)  
Antiguo 20/01/2015, 14:05
 
Fecha de Ingreso: octubre-2013
Mensajes: 24
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: seleccion de radio button

amigo pido la ayuda por que realmente no se nada de javascript ;s
ya lo habia hecho de todas maneras gracias..

Etiquetas: button, html, input, radio, seleccion, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:48.