View Single Post
  #2 (permalink)  
Old 03-27-2008, 12:20 PM
chili5's Avatar   
chili5 chili5 is offline
Code Warrior
 
Join Date: Mar 2008
Age: 15
Posts: 3,450
Credits: 312
Rep Power: 31
chili5 is a name known to allchili5 is a name known to allchili5 is a name known to allchili5 is a name known to allchili5 is a name known to allchili5 is a name known to all
Default Re: Javascript to Add a Text Input field

HTML Code:
<html>
<head>
<title></title>
<script language="javascript">
fields = 0;
function addInput() {
if (fields != 10) {
document.getElementById('text').innerHTML += "<input type='file' value='' /><br />";
fields += 1;
} else {
document.getElementById('text').innerHTML += "<br />Only 10 upload fields allowed.";
document.form.add.disabled=true;
}
}
</script>
</head>
<body>
<form name="form">
<input type="button" onclick="addInput()" name="add" value="Add input field" />
</form>
<div id="text">

</div>
</body>
</html>
This will add an extra file upload field everytime you click the button and put it on the next line. Until it gets to 10 upload fields, where it won't add anymore and then it will disable the add more buttons.

Quote:
document.getElementById('text').innerHTML += "<input type='file' value='' /><br />";
You can change the stuff in the double quotes after to change how your input field appears.

Quote:
if (fields != 10) {
change the 10 in this line to the number of fields you want to allow.

Last edited by chili5; 03-27-2008 at 05:51 PM.
Reply With Quote