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>

Link to comment
Share on other sites

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" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.