******

good day im new to this forum and i hope you can help me, I'm new to javascript
i need to achieve a few things. my goal is to put a running timer for each text box generated 
ive read tutorials online and tested some codes and so far its been a big help for me. but I'm pretty confused on how to achieve 
my goal below code is what i've done so far

<html>
<head>
<title>test</title>
<script type="text/javascript">

var myVar=setInterval(function(){myTimer()},1000);

function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}


    var counter = 0;
    function addNew() {
    // Get the main Div in which all the other divs will be added
    var mainContainer = document.getElementById('mainContainer');
    // Create a new div for holding text and button input elements
    var newDiv = document.createElement('div');
    // Create a new text input
    var newText = document.createElement('input');
    newText.type = "input";
    newText.value = counter;
    newText.value =document.getElementById("demo").innerHTML=myTimer(); //I'm hoping to insert the timer here to generate while adding text box

    // Create a new button input
    var newDelButton = document.createElement('input');
    newDelButton.type = "button";
    newDelButton.value = "Delete";
    // Append new text input to the newDiv
    newDiv.appendChild(newText);

    // Append new button input to the newDiv
    newDiv.appendChild(newDelButton);
    // Append newDiv input to the mainContainer div
    mainContainer.appendChild(newDiv);
    counter++;
    // Add a handler to button for deleting the newDiv from the mainContainer
    newDelButton.onclick = function() {
    mainContainer.removeChild(newDiv);
    }
    }
    </script>
    </head>
    <body >
    <div id="mainContainer">
    <div><input type="text" ><input type="button" value="Add" onClick="addNew()"></div>
    <p id="demo">This is a paragraph.</p>


    </div>
    </body>
    </html>

    Everytime I generate or add the text box I get undefined error and not much description, I get confused calling the function using innerHTML.

     thank you in advance.******

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

ive read tutorials online and tested some codes and so far its been a big help for me. but I'm pretty confused on how to achieve my goal below code is what i've done so far

What is the link to the tutorial? I want to see the original code before you make those changes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.