javascript - Input not appearing when executing function -
i need when option "otros" of select clicked, input appears. so, have made script not working fine (input not appear).
html/php
<select onclick='atencion_otros()' id="atencion" name="atencion"> <option selected>atenciĆ³n</option> <option>otros</option> <?php if($copy){ echo '<option selected>' . $atencion . '</option>'; $result = mysqli_query($con,"select * `contactos_pmt` order nombre_contacto"); while($row = mysqli_fetch_array($result)){ ?> <option> <?php echo $row['nombre_contacto']; ?> </option> <br><br><?php } } if($cargar_cliente){ $result = mysqli_query($con,"select * `contactos_pmt` nombre_empresa = '$nombre_cliente' order nombre_contacto"); while($row = mysqli_fetch_array($result)){ ?> <option selected> <?php echo $row['nombre_contacto']; ?> </option> <br><br><?php } } ?> </select> <input onkeypress="return event.keycode != 13;" style="display:none;" id="atencion_otros" name="atencion_otros" placeholder="atenciĆ³n" />
javascript
<script type="text/javascript"> function atencion_otros() { if (document.getelementbyid('atencion').value == 'otros') { document.getelementbyid('atencion_otros').style.display = 'block'; } else { document.getelementbyid('atencion_otros').style.display = 'none'; } } </script>
do have idea of why input not appearing?
first add value attributes in <option>
.
then add event listener.
document.addeventlistener('domcontentloaded',function() { document.getelementbyid('atencion').onchange=atencion_otros; },false);
now function
function atencion_otros() { if (document.getelementbyid('atencion').value == 'otros') { document.getelementbyid('atencion_otros').style.display = 'block'; } else { document.getelementbyid('atencion_otros').style.display = 'none'; } }
now remove onclick attribute <select>
.
Comments
Post a Comment