HTML Element

If your a member of codenstuff then this is the main place to be. Get together..talk..chat and ponder. Have fun. Chill out. Play games.
7 posts Page 1 of 1
Contributors
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

HTML Element
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
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: HTML Element
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>&nbsp;</div>";
}
</script>
<body>
<span id="container"></span>
<input type="button" value="Add more" onclick="clicked()" />
</body>
Last edited by mandai on Sun Nov 07, 2010 5:24 pm, edited 1 time in total.
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: HTML Element
Codex
no mandai, i already have that code, but then it adds unlimited textbox's, i want to limit it.
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: HTML Element
mandai
You could add a counter for the number of times clicked if you want to limit it.
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: HTML Element
Codex
sorry but im not an advanced html/php coder, so what will the code be :D ?
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: HTML Element
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
}
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: HTML Element
Codex
Thank You mandai
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
7 posts Page 1 of 1
Return to “Codenstuff boardroom”