Jump to content

How to Get the Content in Javascript Dynamic Textbox


gagards200

Recommended Posts

The syntax below will give you 1 textbox and one button... In everytime I will click the button it will populate 1 textbox at a time...

 

Now I need your help on how to get the content each of the textbox that has been populated..

 

Your urgent help is highly appreciated and GOD Bless Always..PHP FREAKS..

 

 

<html>

<head>

<title>Dynamic Form</title>

<script language="javascript">

function changeIt()

{

var i = 1;

my_div.innerHTML = my_div.innerHTML +"<br><input type='text' name='mytext'+ i>"

 

}

 

</script>

 

 

</head>

<body>

 

<form name="form" action="post" method="">

<input type="text" name=t1>

<input type="button" value="test" onClick="changeIt()">

<div id="my_div"></div>

 

</body>

 

</html>

You could use document.getElementsByTagName

 

Here is an example read the comments to understand how it works:

 

<script>
window.onload = function() {
    // get input elements
    var inputElements = document.getElementsByTagName('input');
    // loop through input elements
    for(var i = 0; i < inputElements.length; i++) {
        // output the value of each element use alert if you're not using firebug
        console.log(inputElements[i]['value']);
    }
}
</script>

<input type="text" value="" name="txt1" />
<input type="text" value="not empty" name="txt2" />
<input type="text" value="" name="txt3" />
<input type="text" value="not empty either" name="txt4" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.