Foros del Web » Programando para Internet » Javascript »

Rescatar Valor

Estas en el tema de Rescatar Valor en el foro de Javascript en Foros del Web. Hola amigos, tengo la siguiente duda que no lo he podido solucionar, resulta que tengo que crear este form pero luego almacenar los datos en ...
  #1 (permalink)  
Antiguo 11/11/2008, 23:51
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Rescatar Valor

Hola amigos, tengo la siguiente duda que no lo he podido solucionar, resulta que tengo que crear este form pero luego almacenar los datos en la BD, con select dependientes

Código PHP:
        <label for="regiones">Regi&oacute;n</label>
        <select name="regiones" id="regiones" class="required" title="Seleccione la regi&oacute;n">
        <option value="" selected="selected">Seleecione</option>
        <?
        $q 
$db->query("SELECT * FROM region ORDER BY reg_nombre ASC");
        while(
$resp $db->fetch($q))     {
        echo 
'<option id="'.$resp[reg_nombre].'" value="'.$resp[reg_id].'">'.$resp[reg_nombre].'</option>'."\n\t\t".'';
        }
        
?>
        </select>*
        </td>

        <td>    
        <label for="territorio">Territorio</label>
        <select id="territorio" name="territorio" class="required" title="Selecciona un territorio">
            <option value="" selected="selected">Seleccione</option>
        </select>*
        </td>
        
        <td>
        <label for="provincia">Provincia</label>                
        <select id="provincia" name="provincia" class="required" title="Selecione la provincia">
            <option value="" selected="selected">Seleccione</option>
        </select>*
        </td>

        <td>        
        <label for="comuna">Comuna</label>                
        <select name="comuna" id="comuna"  class="required" title="Seleccione la comuna" >
            <option value="" selected="selected">Seleccione</option>
        </select>*
        </td>
    
        <td><label for="localidad">Localidad</label>                
        <select name="localidad" id="localidad" onchange="agegaopt(this)" >
            <option value="" selected="selected">Seleccione</option>
        </select>*    
        </td>        
        
        <td>
        <input type="button" value="Agregar"  onclick="javascript:addrow2()">
        </td>

Código PHP:
// javascript
// creando una tabla dinamicamente a partir de los select regiones

var cont=1;
function 
addrow(tc1,tc2,tc3,tc4,tc5,tc6,tc7,region,territorio,provincia,comuna,localidad) {
var 
tbl document.getElementById('tabla');
var 
row document.createElement('tr');
var 
c0 document.createElement('td')
c0.innerHTML=cont;
cont++;
var 
c1 document.createElement('td')
c1.innerHTML=tc1;
var 
c2 document.createElement('td')
var 
c3 document.createElement('td')
var 
c4 document.createElement('td')
var 
c5 document.createElement('td')

    var 
c7 document.createElement('input')
        
c7.type 'text'
        
c7.name 'montos[]'

    
var region document.createElement('input'// regiones 
        
region.type 'hidden'
        
region.name 'regiones[]'
        
region.value document.getElementById('regiones').value

    
var    territorio document.createElement('input'// territorio
        
territorio.type 'hidden'
        
territorio.name 'territorios[]'
        
territorio.value document.getElementById('territorio').value

    
var provincia document.createElement('input'// provincia
        
provincia.type 'hidden'
        
provincia.name 'provincias[]'
        
provincia.value document.getElementById('provincia').value

    
var comuna document.createElement('input'// comuna
        
comuna.type 'hidden'
        
comuna.name 'comunas[]'
        
comuna.value document.getElementById('comuna').value

    
var localidad document.createElement('input'// provincia
        
localidad.type 'hidden'
        
localidad.name 'localidades[]'
        
localidad.value document.getElementById('localidad').value

        
// crear campos que se crean en la tabla dinamicamente
        
c2.innerHTML=tc2;
        
c3.innerHTML=tc3;
        
c4.innerHTML=tc4;
        
c5.innerHTML=tc5;
        
c7.innerHTML=tc7;

            
// campos ocultos
            
region.innerHTML=region;
            
territorio.innerHTML=territorio;
            
provincia.innerHTML=provincia;
            
comuna.innerHTML=comuna;
            
localidad.innerHTML=localidad;

        
// crear campos que se crean en la tabla dinamicamente
        
row.appendChild(c0);
        
row.appendChild(c1);
        
row.appendChild(c2);
        
row.appendChild(c3);
        
row.appendChild(c4);
        
row.appendChild(c5);
        
row.appendChild(c7);

            
// campos ocultos
            
row.appendChild(region);
            
row.appendChild(territorio);
            
row.appendChild(provincia);
            
row.appendChild(comuna);
            
row.appendChild(localidad);


tbl.appendChild(row);
}

function 
addrow2() {
var 
frm document.getElementById('form');
        
addrow// agregando filas
        
frm.regiones.value,
        
frm.territorio.value,
        
frm.provincia.value,
        
frm.comuna.value,
        
frm.localidad.value
        
); // paso los datos del formulario a la tabla

Código PHP:
// formulario en html
<table>
    <
tr>
        <
td>
        <
label for="regiones">Regi&oacute;n</label>
        <
select name="regiones" id="regiones" class="required" title="Seleccione la regi&oacute;n">
        <
option value="" selected="selected">Seleecione</option>
        <
option id="ANTOFAGASTA" value="2">ANTOFAGASTA</option>

        <
option id="COPIAPO" value="3">COPIAPO</option>
        <
option id="COQUIMBO" value="4">COQUIMBO</option>
        <
option id="TARAPACA" value="1">TARAPACA</option>
        <
option id="VALPARAISO" value="5">VALPARAISO</option>
                </
select>*
        </
td>

        <
td>    
        <
label for="territorio">Territorio</label>

        <
select id="territorio" name="territorio" class="required" title="Selecciona un territorio">
            <
option value="" selected="selected">Seleccione</option>
        </
select>*
        </
td>
        
        <
td>
        <
label for="provincia">Provincia</label>                
        <
select id="provincia" name="provincia" class="required" title="Selecione la provincia">
            <
option value="" selected="selected">Seleccione</option>

        </
select>*
        </
td>

        <
td>        
        <
label for="comuna">Comuna</label>                
        <
select name="comuna" id="comuna"  class="required" title="Seleccione la comuna" >
            <
option value="" selected="selected">Seleccione</option>
        </
select>*
        </
td>
    
        <
td><label for="localidad">Localidad</label>                
        <
select name="localidad" id="localidad" onchange="agegaopt(this)" >

            <
option value="" selected="selected">Seleccione</option>
        </
select>*    
        </
td>        
        
        <
td>
        <
input type="button" value="Agregar"  onclick="javascript:addrow2()">
        </
td>
</
table
Resulta que el dato que quiero mostrar en la tabla es el de la ID del listbox, pero me muestra el name, alguien me podrá ayudar, se lo agradeceria muchisimo

Saludos..
  #2 (permalink)  
Antiguo 12/11/2008, 12:35
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Rescatar Valor

nadie ???? buuu
  #3 (permalink)  
Antiguo 12/11/2008, 16:00
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Pregunta Respuesta: Rescatar Valor

No he leído exhaustivamente el código, pero por lo que veo, estás mostrando el value de la opción seleccionada en la lista, ¿qué es exactamente lo que quieres mostrar? ¿a qué te refieres con id?.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #4 (permalink)  
Antiguo 12/11/2008, 19:59
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Rescatar Valor

lo que exactamente quiero mostrar es el texto del option

Salu2
  #5 (permalink)  
Antiguo 12/11/2008, 20:01
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Rescatar Valor

Entonces, en lugar de usar el atributo .value, usa .text
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #6 (permalink)  
Antiguo 13/11/2008, 12:42
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Rescatar Valor

bueno ya lo arregle se los dejo

Código PHP:
function agregar_fila(origen,destino) {
    
///////////////////////////////////////////

    
var region   origen.regiones.value;
    var 
territorio origen.territorio.value;
    var 
provincia origen.provincia.value;
    var 
comuna origen.comuna.value;
    var 
localidad origen.value;
    
    var 
nuevo_indice destino.rows.length;

    var 
fila;
    var 
celda;
    var 
valor;
    
    
fila destino.insertRow(nuevo_indice);
    
fila.style.background "white";
    
    
///////////////////////////////////////////

    
celda fila.insertCell(0);
    
valor document.createElement("input");
        
valor.type "checkbox";
        
valor.id "marca";
        
valor.name "marca";
        
valor.value nuevo_indice;
    
celda.appendChild(valor);

    
///////////////////////////////////////////

    
celda fila.insertCell(1);
    var 
region document.createElement('input'
        
region.type 'hidden'

    
var region_id document.getElementById('regiones');
        var 
txtTextObj document.getElementById('txtText');
        
    var 
selIndex region_id.selectedIndex;
        
region.value region_id.options[selIndex].text;    

    
valor document.createTextNode(region.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(2);
    var 
territorio document.createElement('input'
        
territorio.type 'hidden'

    
var territorio_id document.getElementById('territorio');
        var 
txtTextObj document.getElementById('txtText');

    var 
selIndex territorio_id.selectedIndex;
        
territorio.value territorio_id.options[selIndex].text;    

    
valor document.createTextNode(territorio.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(3);
    var 
provincia document.createElement('input'
        
provincia.type 'hidden'

    
var provincia_id document.getElementById('provincia');
        var 
txtTextObj document.getElementById('txtText');

    var 
selIndex provincia_id.selectedIndex;
        
provincia.value provincia_id.options[selIndex].text;    

    
valor document.createTextNode(provincia.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(4);
    var 
comuna document.createElement('input'
        
comuna.type 'hidden'

    
var comuna_id document.getElementById('comuna');
        var 
txtTextObj document.getElementById('txtText');

        
    var 
selIndex comuna_id.selectedIndex;
        
comuna.value comuna_id.options[selIndex].text;    

    
valor document.createTextNode(comuna.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(5);
    var 
localidad document.createElement('input'
        
localidad.type 'hidden'
        
localidad.name 'localidad[]'

    
var localidad_id document.getElementById('localidad');
        var 
txtTextObj document.getElementById('txtText');
        
    var 
selIndex localidad_id.selectedIndex;
        
localidad.value localidad_id.options[selIndex].text;    

    
valor document.createTextNode(localidad.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(6);
    var 
latitud document.createElement('input'// latitud
        
latitud.type 'text'
        
latitud.name 'latitud[]'
        
        
celda.appendChild(latitud);

    
///////////////////////////////////////////

    
celda fila.insertCell(7);
    var 
longitud document.createElement('input'// longitud
        
longitud.type 'text'
        
longitud.name 'longitud[]'
        
        
celda.appendChild(longitud);

    
///////////////////////////////////////////
    
    
celda fila.insertCell(8);
    var 
monto document.createElement('input'// montos
        
monto.type 'text'
        
monto.name 'montos[]'
        
        
celda.appendChild(monto);

    
///////////////////////////////////////////

    
var    region document.createElement('input'// territorio
        
region.type 'hidden'
        
region.name 'regiones[]'

    
var region_id document.getElementById('regiones');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex region_id.selectedIndex;
        
region.value region_id.options[selIndex].id;

        
region.innerHTML=region;
        
celda.appendChild(region);            

    
///////////////////////////////////////////

    
var    territorio document.createElement('input'// territorio
        
territorio.type 'hidden'
        
territorio.name 'territorios[]'

    
var territorio_id document.getElementById('territorio');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex territorio_id.selectedIndex;
        
territorio.value territorio_id.options[selIndex].id;

        
territorio.innerHTML=territorio;
        
celda.appendChild(territorio);            

    
///////////////////////////////////////////

    
var    provincia document.createElement('input'// territorio
        
provincia.type 'hidden'
        
provincia.name 'provincias[]'

    
var provincia_id document.getElementById('provincia');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex provincia_id.selectedIndex;
        
provincia.value provincia_id.options[selIndex].id;

        
provincia.innerHTML=provincia;
        
celda.appendChild(provincia);            

    
///////////////////////////////////////////

    
var    comuna document.createElement('input'// territorio
        
comuna.type 'hidden'
        
comuna.name 'comunas[]'

    
var comuna_id document.getElementById('comuna');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex comuna_id.selectedIndex;
        
comuna.value comuna_id.options[selIndex].id;

        
comuna.innerHTML=comuna;
        
celda.appendChild(comuna);            

    
///////////////////////////////////////////

    
var    localidad document.createElement('input'// territorio
        
localidad.type 'hidden'
        
localidad.name 'localidades[]'

    
var localidad_id document.getElementById('localidad');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex localidad_id.selectedIndex;
        
localidad.value localidad_id.options[selIndex].id;

        
localidad.innerHTML=localidad;
        
celda.appendChild(localidad);            
        
    
///////////////////////////////////////////    

}

function 
remover_filas_marcadas(origen) {
    
///////////////////////////////////////////

    
var inputs origen.getElementsByTagName("input");
    var 
checkboxes = new Array();
    var 
chk_cuenta 0;
    
    
///////////////////////////////////////////

    
for (i=0i<inputs.lengthi++)
    {
        if (
inputs[i].type == "checkbox" &&
            
inputs[i].id == "marca" &&
            
inputs[i].checked)
        {
            
checkboxes[chk_cuenta] = inputs[i];
            
chk_cuenta ++;
        }
    }

    
///////////////////////////////////////////

    
for (i=0i<checkboxes.lengthi++)
    {
        
origen.deleteRow(checkboxes[i].value 1*i);
    }    

    
///////////////////////////////////////////
    
    
corregir_indices_tabla(origen);

    
///////////////////////////////////////////
}

function 
corregir_indices_tabla(origen) {
    
///////////////////////////////////////////

    
var inputs origen.getElementsByTagName("input");
    
    
///////////////////////////////////////////

    
for (i=0i<inputs.lengthi++)
    {
        if (
inputs[i].type == "checkbox" &&
            
inputs[i].id == "marca")
        {
            
inputs[i].value 1;
        }
    }

    
///////////////////////////////////////////

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 17:43.