Mit diesem JavaScript können Sie in Formularen , durch den User ein neues Eingabefeld zufügen lassen und auch wieder entfernen.
Autor: Husay
zur Demo
in <head> zufügen
<script type="text/javascript">
<!-- by Husay communitxt.net / http://www.scriptwelt.org -->
var arrInput = new Array(0);
var arrInputValue = new Array(0);
function addInput() {
arrInput.push(arrInput.length);
arrInputValue.push("");
display();
}
function display() {
document.getElementById('parah').innerHTML="";
for (intI=0;intI<arrInput.length;intI++) {
document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
}
}
function saveValue(intId,strValue) {
arrInputValue[intId]=strValue;
}
function createInput(id,value) {
return "<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>";
}
function deleteInput() {
if (arrInput.length > 0) {
arrInput.pop();
arrInputValue.pop();
}
display();
}
</script>
in <body> einfügen
<p id="parah">Click below to dynamically create/remove input boxes in this field</p>
<a href="javascript:addInput()">Add more input field(s)</a><br>
<a href="javascript:deleteInput()">Remove field(s)</a>
|