Home How do i get the value of dynamic input fields from javascript function?
Reply: 0

How do i get the value of dynamic input fields from javascript function?

user2202 Published in April 26, 2018, 9:01 pm

I am trying to make a dynamic form using a javascript function, but i'm amateur on this, so i'm not sure how to collect the inputs values, considering is a dynamic function. This is the HTML part:

   Amount of people: <input type="text" id="member" name="member" value=""><br />
   <button id="btn" onclick="addinputFields()">Show</button>
<form action="{{ url_for('red_preferente') }}" method="post">
     <div id="mydiv"/><br />
     <input type="submit" value="Quote"/>

And this is the JS function "addinputFields", im calling above

function addinputFields(){
var number = document.getElementById("member").value;

  for (i=0;i<number;i++){
      var campo_1 = document.createElement("output");
      campo_1.type = "text";
      campo_1.value = " Nombre: ";

      var nombre = document.createElement("input");
      nombre.type = "text";
      nombre.id = "name"

      var campo_2 = document.createElement("output");
      campo_2.type = "text";
      campo_2.value = " Edad: ";

      var edad = document.createElement("input");
      edad.type = "text";
      edad.id = "age"

      var campo_3 = document.createElement("output");
      campo_3.type = "text";
      campo_3.value = " Modalidad: ";

      var modalidades = ["Titular","Asegurado","Dependiente"];
      var listado = document.createElement("select");
      listado.id = "mySelect";

      for (var x = 0; x < modalidades.length; x++) {
          var option = document.createElement("option");
          option.value = modalidades[x];
          option.text = modalidades[x];

I'm trying to use "document.getElementById('mydiv').value" to have the input value, but i receive none value

I need each one of the input value of vars: nombre, edad, listado. Any idea?

Thanks a lot for help!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.248292 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO