el_dorito
03-01-2005, 11:12 AM
Hi,
I'm trying to make an dynamic input form.
This is the idea.
When the user enters the form there are two form elements present
(1 text input and one teaxtarea).
Below these is a button saying "add more".
Each time the user prese's this button there are two form elements (like those before)
that will be created (whitout refresh).
The user can generate as mutch as he wants.
Till this par al works fine.
I have the following code:
<script type="text/javascript">
var i=2
function CreateFields() {
document.getElementById("my_div").innerhtml=document.getElementById("my_div") .innerHTML+ '<span class="left" style="width:175px"><label for="option_name'+ i +'">'+ i +' ) Optie naam:</label><br><input type="text" name="option_name'+ i +'" id="option_name'+ i +'" size="20" maxlength="20" /></span><span class="right" style="width:315px" ><label for="option_description'+ i +'">Optie beschrijving</label><br><textarea cols="35" rows="10" name="option_description'+ i +'"></textarea></span><div style="clear:both;width:500px;height:2px"></div>';
i=i+1
}
</script>
This function is called each time the button is pressed.
The Problem:
If the user enters values in the text input an textarea and presses the button to create two more fields
The enterd values (of the previous fields) are DELETED!!. Not something that you want to happen.
What can I do to preven this?
Thanks for the help
I'm trying to make an dynamic input form.
This is the idea.
When the user enters the form there are two form elements present
(1 text input and one teaxtarea).
Below these is a button saying "add more".
Each time the user prese's this button there are two form elements (like those before)
that will be created (whitout refresh).
The user can generate as mutch as he wants.
Till this par al works fine.
I have the following code:
<script type="text/javascript">
var i=2
function CreateFields() {
document.getElementById("my_div").innerhtml=document.getElementById("my_div") .innerHTML+ '<span class="left" style="width:175px"><label for="option_name'+ i +'">'+ i +' ) Optie naam:</label><br><input type="text" name="option_name'+ i +'" id="option_name'+ i +'" size="20" maxlength="20" /></span><span class="right" style="width:315px" ><label for="option_description'+ i +'">Optie beschrijving</label><br><textarea cols="35" rows="10" name="option_description'+ i +'"></textarea></span><div style="clear:both;width:500px;height:2px"></div>';
i=i+1
}
</script>
This function is called each time the button is pressed.
The Problem:
If the user enters values in the text input an textarea and presses the button to create two more fields
The enterd values (of the previous fields) are DELETED!!. Not something that you want to happen.
What can I do to preven this?
Thanks for the help