Comunidad de diseño web y desarrollo en internet online

validar y grabar textbox creado x combo

Citar            
MensajeEscrito el 19 Oct 2011 07:28 pm
tengo este script y funciona bien: lo que hace es crear un text box segun el item(7) que seleccione del combobox
...
<tr>
<td width="50%" nowrap="nowrap" align="right">Estudios <span class="campo_obligatorio">*</span></td>
<td nowrap="nowrap">
<select name="est" id="est" onchange="if(this.value=='7'){document.getElementB yId('inputOculto').style.display='block'}else{docu ment.getElementById('inputOculto').style.display=' none'}">
<option value="-2">- Seleccione -</option>
<?php
$sel_ee="select *from estudios";
$rel_ee=mysql_query($sel_ee,$link);
while($db_est=mysql_fetch_array($rel_ee)){
echo '<option value="'.$db_est["id_estudios"].'">'.$db_est["concepto"].'</option>';
}
?>
</select>
</td>
<td align="left" nowrap="nowrap">
<input type="text" id="inputOculto" style="display:none" />
</td>
</tr>

como hago para validar este textbox y luego grabar en una tabla de la bd


probe con esto pero no sale pagina error
if(document.getElementById("estudio").value == -2){
texto = texto + " - Escoger el Estudio\n";
error++;
if(this.value='7' and document.getElementById("inputOculto").value.lengt h == 0){
texto = texto + "Escogio de la lista el item 'Otros Estudio' pero No Digito en el cuadro de texto que aparecio cual es su otro estudio, Digite porfavor,\n";
error++;
}
}

Por angelo27

Claber

136 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Oct 2011 08:19 pm
tienes un erro en el "AND " en javascript se utiliza el &&

<html>
<head>
<title></title>
</head>
<script>
function revisa(obj){
if(obj.value=='7'){
document.getElementById('inputOculto').style.display='block';
}else{
document.getElementById('inputOculto').style.display='none';
}
}
function aer(){
if(this.value='7' && document.getElementById("inputOculto").value.length == 0){
alert("blabla");
}
}
</script>
<body>
<form name="formulario">
<table>
<tr>
<td width="50%" nowrap="nowrap" align="right">Estudios <span class="campo_obligatorio">*</span></td>
<td nowrap="nowrap">
<select name="est" id="est" onchange="javascript:revisa(this)">
<option value="-2">- Seleccione -</option>
<option value="7"> el 7 </option>
</select>
</td>
<td align="left" nowrap="nowrap">
<input type="text" id="inputOculto" style="display:none" />
</td>
</tr>
</table>
<input type="button" value="Revisar script" onclick="javascript:aer()">
</form>
</body>
</html>

Por machvk

15 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Oct 2011 10:53 pm
no puedo preguntar por obj.value=='7')
porque para llenar el combo uso echo '<option value="'.$db_est["id_estudios"].'">'.$db_est["concepto"].'</option>';

como reemplazo
<option value="7"> el 7 </option>

por:
echo '<option value="'.$db_est["id_estudios"].'">'.$db_est["concepto"].'</option>';

Por angelo27

Claber

136 de clabLevel



 

firefox
Citar            
MensajeEscrito el 20 Oct 2011 02:24 pm
no entendi bien lo ultimo , pero en un select te puedes mover por todas las opciones ya que es una arreglo, incluso puedes moverte por todo el formulario como si fuera un gran arreglo con multidimensiones.

por ejemplo si tienes un select con id "sfrm1" en el script () puedes recorrer todo el select preguntando por cual esta seleccionado. a modo de ejemplo.

var s1 = document.getElementById(sfrm1);
for(i=s1.options.length-1;i>=0;i--){
s1.options[i].selected=true;
}

Por machvk

15 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.