0

input radio script

function adiradio() {
  var text = document.getElementById("txopcion").value; //obtiene el text para la opcion
  if (text != '') { //que no se pueda poner opciones vacias
    var node = document.createElement("P"); //etiqueta p
    var x = document.createElement("INPUT"); //crea un input
    var textnode = document.createTextNode(text); //asigna el text 
    x.setAttribute("type", "radio"); //hace que type del input sea radio
    x.setAttribute("name", "alternati");
    x.setAttribute("value", text);
    node.appendChild(x);
    node.appendChild(textnode);
     document.getElementById("adicionarR").appendChild(node);
  }
}
<form action="pregunta-quest.php" method="post">
  <input type="text" id="txopcion" placeholder="Escribe Opción">
  <button type="button" onclick="adiradio()">agregar</button>
  <br>
  <span id="adicionarR"></span>
</form>

Pregunta-quest.php

$valAlter=$_POST['alternati']; //line 11

Notice: Undefined index: alternati in C:\xampp\htdocs\phpLogin\pregunta-quest.php on line 11

RobG
  • 142,382
  • 31
  • 172
  • 209
  • Have you looked at your js console? Perhaps it's a syntax error since you are missing a `}`. – Rasclatt Jan 30 '17 at 01:00
  • Yeah. Like the second curly brace – 16kb Jan 30 '17 at 01:04
  • You are trying to append a paragraph element (*node*) to a span element (`document.getElementById("adicionarR")`), which is not allowed. – RobG Jan 30 '17 at 01:12
  • I fixed your formatting and the typo, the code "works" (though the paragraph is likely inserted after the span, not inside it). Note that inserting a single radio button is a bit dysfunctional, once it's selected, it can't be unselected unless you provide a reset button to reset the form. – RobG Jan 30 '17 at 01:19

0 Answers0