JavaScript - [Duda] Acerca de los radio buttons

 
Vista:
sin imagen de perfil

[Duda] Acerca de los radio buttons

Publicado por Gustavo (3 intervenciones) el 08/11/2016 05:23:22
Buenas amigos, espero no molestar y necesito de su ayuda. Cuestión que estoy realizando una pagina y necesito saber cual elemento de un radio button esta seleccionado, pero no he podido. Serian tan amables de ayudarme. Adjunto el código y la pagina para que le echen un ojo. De antemano muchas gracias y saludos. Lo que necesito es que si el radio button "sr" está seleccionado, me imprima en la caja de texto. tratamiento : sr. Espero con ansias la respuesta. Saludos y un abrazo a distancia

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Formulario sobre datos</title>
</head>
 
<body>
<div id="contenedor_principal">
  <div id="formulario">
    <form>
      <table width="200" border="0">
        <tbody>
          <tr>
            <td>Tratamiento</td>
            <td><input type="radio" name="Opcion" id="op1" value="Sr">
              Sr</td>
            <td><input type="radio" name="Opcion" id="op2" value="Sra">
              Sra</td>
          </tr>
          <tr>
            <td>Nombre:</td>
            <td colspan="2"><input type="text" name="nombre" id="nombre"></td>
          </tr>
          <tr>
            <td>Apellido:</td>
            <td colspan="2"><input type="text" name="apellido" id="apellido"></td>
          </tr>
          <tr>
            <td>Direccion: </td>
            <td colspan="2"><input type="text" name="direccion" id="direccion"></td>
          </tr>
          <tr>
            <td>Ciudad</td>
            <td colspan="2"><select name="menu" id="menu">
                <option id="op1" value="op1">San Jose</option>
                <option id="op2" value="op2">Cartago</option>
                <option id="op3" value="op3">Alajuela</option>
                <option id="op4" value="op4">Puntarenas</option>
                <option id="op5" value="op5">Guanacaste</option>
              </select></td>
          </tr>
          <tr>
            <td> Preferencias </td>
            <td colspan="2"><input type="checkbox" name="prefe" value="Libros">
              Libros
              <input type="checkbox" name="prefe" value="Peliculas">
              Peliculas </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="button" id="enviar" name="enviar" value="Enviar" onClick="escriba()"></td>
            <td><input type="button" id="cancelar" name="cancelar" value="Cancelar" onclick="escriba2()"></td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>
  <div id="foto"> <img id="imagen" src="../Recursos/img/foto.png" style="width: 100px; height: 100px;" > </div>
  <div id="areatexto">
    <textarea name="textarea" id="textarea" cols="50" rows="4"></textarea>
  </div>
</div>
</body>
<script type="text/javascript">
 function escriba(){
	 var datos = "Datos Introducidos.";
   if(document.getElementById("menu").value == "op1"){
    document.getElementById("textarea").value += (datos + "\n" + "Nombre: " + document.getElementById("nombre").value + "\n" + "Apellido: " + document.getElementById("apellido").value + "\n" + "Direccion: " + document.getElementById("direccion").value + "\n" + "Provincia: San Jose" + "\n");
 
   }else if (document.getElementById("menu").value == "op2"){
    document.getElementById("textarea").value += (datos + "\n" + "Nombre: " + document.getElementById("nombre").value + "\n" + "Apellido: " + document.getElementById("apellido").value + "\n" + "Direccion: " + document.getElementById("direccion").value + "\n" + "Provincia: Cartago" + "\n");
    document.getElementById("imagen").src="../Recursos/img/foto2.png"
 
   }else if (document.getElementById("menu").value == "op3") {
    document.getElementById("textarea").value += (datos + "\n" + "Nombre: " + document.getElementById("nombre").value + "\n" + "Apellido: " + document.getElementById("apellido").value + "\n" + "Direccion: " + document.getElementById("direccion").value + "\n" + "Provincia: Alajuela" + "\n");
 
   }else if (document.getElementById("menu").value == "op4") {
     document.getElementById("textarea").value += (datos + "\n" + "Nombre: " + document.getElementById("nombre").value + "\n" + "Apellido: " + document.getElementById("apellido").value + "\n" + "Direccion: " + document.getElementById("direccion").value + "\n" + "Provincia: Puntarenas" + "\n");
   }else if (document.getElementById("menu").value == "op5") {
    document.getElementById("textarea").value += (datos + "\n" + "Nombre: " + document.getElementById("nombre").value + "\n" + "Apellido: " + document.getElementById("apellido").value + "\n" + "Direccion: " + document.getElementById("direccion").value + "\n" + "Provincia: Guanacaste" + "\n");
 
   }
}
 
</script>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder