Page 1 of 1
HTML Element
Posted: Sun Nov 07, 2010 3:34 pm
by Codex
Hello Coders
I need help with html, i'm trying to add an element to a form.
So basically i got a textbox and i got a button under it thats says "add more" and onclick i want it to add a new textbox above the button, under the textbox.
+rep for best answer
Thanks
CodexVideos
Re: HTML Element
Posted: Sun Nov 07, 2010 5:19 pm
by mandai
Is this what you are after?
Code: Select all<script type="text/javascript">
function clicked()
{
var container = document.getElementById("container");
container.innerHTML += '<input type="text" /> ';
container.innerHTML += "<div> </div>";
}
</script>
<body>
<span id="container"></span>
<input type="button" value="Add more" onclick="clicked()" />
</body>
Re: HTML Element
Posted: Sun Nov 07, 2010 5:23 pm
by Codex
no mandai, i already have that code, but then it adds unlimited textbox's, i want to limit it.
Re: HTML Element
Posted: Sun Nov 07, 2010 5:25 pm
by mandai
You could add a counter for the number of times clicked if you want to limit it.
Re: HTML Element
Posted: Sun Nov 07, 2010 5:31 pm
by Codex
sorry but im not an advanced html/php coder, so what will the code be

?
Re: HTML Element
Posted: Sun Nov 07, 2010 9:50 pm
by mandai
Within the script tag you would add:
var count = 0;
Then within the clicked event you would add:
if (count < 3)//if you only want 3 text inputs max.
{
count++;
//rest of the clicked event here
}
Re: HTML Element
Posted: Mon Nov 08, 2010 3:11 pm
by Codex
Thank You mandai