Foros del Web » Programando para Internet » Javascript »

Ocultar campo

Estas en el tema de Ocultar campo en el foro de Javascript en Foros del Web. Hola a todos espero que estén bien. tengo una pequeña duda, tengo este codigo @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original < tr >     ...
  #1 (permalink)  
Antiguo 24/01/2012, 16:14
Avatar de mexbale  
Fecha de Ingreso: septiembre-2010
Ubicación: Iztapalapa
Mensajes: 146
Antigüedad: 13 años, 7 meses
Puntos: 1
Ocultar campo

Hola a todos espero que estén bien.

tengo una pequeña duda, tengo este codigo

Código HTML:
Ver original
  1. <tr>
  2.       <td>PROCEDIMIENTO PARA LA EXPULSIÓN O EXTRACCIÓN</td>
  3.       <td><div align="right">
  4.         <select name="PROCE" id="PROCE">
  5.                 <option selected="selected">
  6.                 <option value="Cesaria">Cesaria</option>
  7.                 <option value="Forceps">Forceps</option>
  8.                 <option value="Legrado">Legrado</option>
  9.                 <option value="Otro">Otro</option>
  10.                 <option value="Ninguno">Ninguno</option>
  11.                 <option value="Se ignora">Se ignora</option>
  12.             </select>
  13.       </div></td>
  14.     </tr>
  15.     <tr>
  16.       <td colspan="2"><div align="right">ESPECIFIQUE
  17.           <input name="PROCE_ESP" type="text" id="PROCE_ESP" onkeypress="return letrasynumeros(event)" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}" size="70" maxlength="100" />
  18.       </div>
  19.       <div align="right"></div></td>
  20.     </tr>

y quisiera que cuando seleccionaran la opción 'OTRO' apareciera el campo llamado PROCE_ESP y cuando seleccionen otra opción que no sea 'OTRO' que se ocultara el campo de PROCE_ESP

espero que me puedan ayudar con esta pequeña duda

de ante mano les doy las gracias buena tarde
  #2 (permalink)  
Antiguo 24/01/2012, 17:10
 
Fecha de Ingreso: febrero-2010
Mensajes: 60
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Ocultar campo

Bueno lo que sugeriría es que con el evento change detectes cuando cambia el select; y obtengas el valor. SI el valor es Otro que ocultes el campo Proce_esp.

Lo podrías hacer muy rápido y fácil con Jquery.
  #3 (permalink)  
Antiguo 24/01/2012, 21:13
 
Fecha de Ingreso: octubre-2010
Mensajes: 107
Antigüedad: 13 años, 6 meses
Puntos: 14
Respuesta: Ocultar campo

seria algo asi, como lo dice clarkpler:

Código Javascript:
Ver original
  1. window.onload=function(){ document.getElementById("PROCE").addEventListener("change",function(){
  2.  
  3. if(document.getElementById("PROCE").value=="Otro") {
  4.     document.getElementById("PROCE_ESP").style.display="block";}
  5. else document.getElementById("PROCE_ESP").style.display="none";
  6.  
  7. },false)}


tienes que agregarle la propiedad style="display:none;" a el input para que este oculto por defecto y solo se muestre al seleccionar "otro" en el select.
  #4 (permalink)  
Antiguo 25/01/2012, 12:35
Avatar de mexbale  
Fecha de Ingreso: septiembre-2010
Ubicación: Iztapalapa
Mensajes: 146
Antigüedad: 13 años, 7 meses
Puntos: 1
Respuesta: Ocultar campo

hola gracias por la ayuda, ya lo oculta pero cuando le doy otro no lo habilita quedo así el código:

Código Javascript:
Ver original
  1. <script>
  2. window.onload=function(){ document.getElementById("PROCE").addEventListener("change",function(){
  3. *
  4. if(document.getElementById("PROCE").value=="Otro") {
  5. * * document.getElementById("PROCE_ESP").style.display="block";}
  6. else document.getElementById("PROCE_ESP").style.display="none";
  7. *
  8. },false)}
  9. </script>

y el input queda asi:

Código HTML:
Ver original
  1. <input name="PROCE_ESP" type="text" id="PROCE_ESP" onkeypress="return letrasynumeros(event)" onkeyup="this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}" value="" size="70" style="display:none" />

pero cuando lo pruebo no me da la función no se si me pueden decir en que estoy mal

de antemano les doy las gracias buena tarde
  #5 (permalink)  
Antiguo 26/01/2012, 06:43
 
Fecha de Ingreso: octubre-2010
Mensajes: 107
Antigüedad: 13 años, 6 meses
Puntos: 14
Respuesta: Ocultar campo

ya lo acabo de probar otra vez y ese mismo codigo(sin los asteriscos) me funciona, lo prove en firefox, chrome, opera, safari e iexplorer y funciona bien en todos.
  #6 (permalink)  
Antiguo 26/01/2012, 10:53
Avatar de mexbale  
Fecha de Ingreso: septiembre-2010
Ubicación: Iztapalapa
Mensajes: 146
Antigüedad: 13 años, 7 meses
Puntos: 1
Respuesta: Ocultar campo

hola MARCASTELEON espero que estés bien.

Ami no me me funciona no se si puedas poner tu código para ver como lo hiciste tu

de antemano te doy las gracias fuerte en tu dia
  #7 (permalink)  
Antiguo 28/01/2012, 16:19
 
Fecha de Ingreso: octubre-2010
Mensajes: 107
Antigüedad: 13 años, 6 meses
Puntos: 14
Respuesta: Ocultar campo

hola,
este es el codigo(igual al que ya puse) que he provado:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5.  
  6.  
  7. window.onload=function(){ document.getElementById("PROCE").addEventListener("change",function(){
  8.  
  9. if(document.getElementById("PROCE").value=="Otro") {
  10.    document.getElementById("PROCE_ESP").style.display="block";}
  11. else document.getElementById("PROCE_ESP").style.display="none";
  12. },false)}
  13.  
  14.  
  15.  
  16.  
  17. </head>
  18.  
  19.  
  20.  
  21.  
  22. <tr>
  23.           <td>PROCEDIMIENTO PARA LA EXPULSIÓN O EXTRACCIÓN</td>
  24.           <td><div align="right">
  25.             <select name="PROCE" id="PROCE" >
  26.                     <option selected="selected">
  27.                     <option value="Cesaria">Cesaria</option>
  28.                     <option value="Forceps">Forceps</option>
  29.                     <option value="Legrado">Legrado</option>
  30.                     <option value="Otro">Otro</option>
  31.                     <option value="Ninguno">Ninguno</option>
  32.                     <option value="Se ignora">Se ignora</option>
  33.                 </select>
  34.           </div></td>
  35.         </tr>
  36.         <tr>
  37.           <td colspan="2"><div align="right">ESPECIFIQUE
  38.               <input name="PROCE_ESP" type="text" id="PROCE_ESP" onkeypress="return letrasynumeros(event)" onkeyup="this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}" value="" size="70" style="display:none" />
  39.           </div>
  40.           </td>
  41.         </tr>
  42. </body>
  43. </html>
  #8 (permalink)  
Antiguo 28/02/2012, 14:52
Avatar de mexbale  
Fecha de Ingreso: septiembre-2010
Ubicación: Iztapalapa
Mensajes: 146
Antigüedad: 13 años, 7 meses
Puntos: 1
Respuesta: Ocultar campo

estimado MARCASTELEON ya lo provee y me jala bien en chrome pero lo pruebo en el iexplorer y no me jala por que sera esto este es mi codigo:


Código HTML:
Ver original
  1. function validar(){
  2.    if(document.getElementById("folio").value==""){
  3.       alert("por favor inserte el folio.");
  4. * * * document.getElementById("folio").focus();
  5. * * * return false;
  6.    }
  7.    if(document.getElementById("cve_med").value==""){
  8.       alert("por favor inserte clave de medicion.");
  9. * * * document.getElementById("cve_med").focus();
  10. * * * return false;
  11.    }
  12.    if(document.getElementById("id").value==""){
  13.       alert("por favor inserte el numero de identificación.");
  14. * * * document.getElementById("id").focus();
  15. * * * return false;
  16.    }
  17.    if(document.getElementById("folio_cer").value==""){
  18.       alert("por favor inserte el folio de certificado.");
  19. * * * document.getElementById("folio_cer").focus();
  20. * * * return false;
  21.    }
  22.    document.getElementById("formulario").submit();
  23. }
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <script type="text/javascript">
  27. function mostrarTab(obj) {
  28.     rolling=obj.scrollTop;
  29.     if(typeof obj.selectionStart == 'number') {
  30.         // Resto de navegadores
  31.         var start = obj.selectionStart;
  32.         var end = obj.selectionEnd;
  33.         obj.value = obj.value.substring(0, start)+"\t";
  34.         obj.value+= obj.value.substring(start, obj.value.length);
  35.         obj.focus();
  36.         obj.selectionStart =  obj.selectionEnd= end + 2;
  37.     }
  38.     else if(document.selection) {
  39.         // Internet Explorer
  40.         obj.focus();
  41.         var range = document.selection.createRange();
  42.         if(range.parentElement() != obj) return false;
  43.         if (range.text != "") {
  44.             if(typeof range.text == 'string'){
  45.                 document.selection.createRange().text ="\t"+range.text;
  46.             }
  47.             else obj.value += "\t";
  48.         }
  49.         else
  50.             obj.value += "\t";
  51.     }
  52.     obj.scrollTop=rolling;
  53. }
  54. function tabulador(form,field)
  55. {
  56. var next=0, found=false
  57. var f=form
  58. //if(event.keyCode!=13) return;
  59. for(var i=0;i<f.length;i++) {
  60.     if(field.name==f.item(i).name){
  61.         next=i+1;
  62.         found=true
  63.         break;
  64.     }
  65. }
  66. //MODIFICACION A LA FUNCION &&  f.item(next).style.display!='none'
  67. while(found){
  68.     if( f.item(next).disabled==false &&  f.item(next).type!='hidden' &&  f.item(next).style.display!='none'){
  69.         f.item(next).focus();
  70.         break;
  71.     }
  72.     else{
  73.         if(next<f.length-1)
  74.             next=next+1;
  75.         else
  76.             break;
  77.     }
  78. }
  79. }
  80. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  81. <title>pruebas</title>
  82. *
  83. window.onload=function(){ document.getElementById("PROCE").addEventListener("change",function(){
  84. *
  85. if(document.getElementById("PROCE").value=="4") {
  86. * *document.getElementById("PROCE_ESP").style.display="block";}
  87. else document.getElementById("PROCE_ESP").style.display="none";
  88. },false)}
  89.  
  90.  
  91.  
  92. </head>
  93. <body onkeypress="return pulsar(event)" bgcolor="#CC99FF" >
  94. <form name="formulario" id="formulario" action="<?=$_SERVER['PHP_SELF']?>" method="post" onSubmit="return validar()">
  95. <table width="850" border="1" align="center">
  96.   <tr>
  97.     <td><div align="center">*Folio</div></td>
  98.     <td><div align="center">
  99.       <input type="text" id="FOLIO" name="FOLIO" size="8" maxlength="8" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  100.     </div></td>
  101.   </tr>
  102.   <tr>
  103.     <td><div align="center">*Clave Medicion</div></td>
  104.     <td><div align="center">
  105.       <input type="text" id="CVE_MED" name="CVE_MED" size="2" maxlength="2" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  106.     </div></td>
  107.   </tr>
  108.   <tr>
  109.     <td><div align="center">Nombre</div></td>
  110.     <td><div align="center">
  111.       <input type="text" id="NOMBRE" name="NOMBRE" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  112.     </div></td>
  113.   </tr>
  114.   <tr>
  115.     <td><div align="center">*ID</div></td>
  116.     <td><div align="center">
  117.       <input type="text" id="ID" name="ID" size="2" maxlength="2" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  118.     </div></td>
  119.   </tr>
  120.   <tr>
  121.     <td><div align="center">*Folio de Certificado</div></td>
  122.     <td><div align="center">
  123.       <input type="text" id="FOLIO_CER" name="FOLIO_CER" size="9" maxlength="9" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  124.     </div></td>
  125.   </tr>
  126.   <tr>
  127.       <td>PROCEDIMIENTO PARA LA EXPULSIÓN O EXTRACCIÓN</td>
  128.       <td>
  129.         <div align="center">
  130.           <select name="PROCE" id="PROCE">
  131.             <option selected="selected">
  132.             <option value="1">Cesaria</option>
  133.             <option value="2">Forceps</option>
  134.             <option value="3">Legrado</option>
  135.             <option value="4">Otro</option>
  136.             <option value="5">Ninguno</option>
  137.             <option value="6">Se ignora</option>
  138.           </select>
  139.           </div></td></tr>
  140.     <tr>
  141. * * * * * <td colspan="2"><div align="right">ESPECIFIQUE
  142. * * * * * * * <input name="PROCE_ESP" type="text" id="PROCE_ESP" onKeyPress="return letrasynumeros(event)" onKeyUp="this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}" value="" size="70" style="display:none" /></div>
  143. * * * * * </td>
  144.     </tr>
  145.   <tr>
  146.     <td colspan="2">
  147.       <div align="center">
  148.         <input type="submit" name="Guardar" value="Guardar" />
  149.         </div></td>
  150.   </tr>
  151. <label><div align="center">los campos marcados con un * son obligatorios</div></label>
  152. </form>
  153. </body>
  154. </html>

lo raro es que dices tu que en iexplorer si te jala y yo lo pruebo y no me jala cual crees que sea el error

de ante mano te doy las gracias
suerte

Última edición por mexbale; 28/02/2012 a las 14:57

Etiquetas: input, campos
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 18:18.