<script language= "javascript" type= "Text/ecmascript" >
//======================
Function: Input file control in the form
Parameters: ParentID---The ID of the parent element to insert the input file control
inputID----The ID of the input file control
//======================
function Createinput (Parentid,inputfileid) {
var parent=$ (ParentID);//Get parent element
var div=document.createelement ("div");//Create a div container to contain the input file
var x=parseint (Math.random () * (80-1)) +1;
var divname=inputfileid+x.tostring ();//The name of the random div container
Div.name=divname;
Div.id=divname;
var aelement=document.createelement ("input"); Create input
Aelement.name=inputfileid;
Aelement.id=inputfileid;
aelement.type= "file";//set type to File
var delbtn=document.createelement ("input");//Create a button to delete the input file
Delbtn.type= "button";
delbtn.value= "Delete";
Delbtn.onclick=function () {removeinput (parentid,divname)};//set the OnClick method for the button
Div.appendchild (aelement);//Add input file to div container
Div.appendchild (DELBTN);//Add the Delete button to the DIV container
Parent.appendchild (div);//Add div container to parent element
}
//============================
function: Delete a div container containing input file
Parameter: ParentID---The parent element ID of the input file control
Deldivid----A div container ID that contains input file
//============================
function Removeinput (parentid,deldivid) {
var parent=$ (ParentID);
Parent.removechild ($ (deldivid));
}
Get elements in a document by element ID
function $ (v) {return document.getElementById (v);}
</script>
<body>
<div align= "left" id= "Div_pic" style= "border:1px solid #CCCCCC" >
<input name= "Picfile" type= "file" id= "Showpicfile" >
</div>
<input type= "button" onclick= "Createinput (' div_pic ', ' picfile ')" name= "button" id= "button" value= "+ continue to add picture" >
</body>