Dynamically add controls for JS

Source: Internet
Author: User

Example 1:
<SCRIPT type = "text/JavaScript">
VaR T = 1;
Function AddFile ()
{
VaR parent = Document. getelementbyid ("more ");
VaR BR = Document. createelement ("Br ");
VaR input = Document. createelement ("input ");
VaR button = Document. createelement ("input ");

Input. type = "file ";
Input. Name = "uploadfile [" + (T ++) + "]. File ";
Input. size = "30 ";
Button. type = "button ";
Button. value = "delete ";

Button. onclick = function ()
{
Parent. removechild (BR );
Parent. removechild (input );
Parent. removechild (button );
};

Parent. appendchild (BR );
Parent. appendchild (input );
Parent. appendchild (button );
}
</SCRIPT>


Example 2:
Automatically add row JS:
Function addonelineonclick (){
VaR ROW = tblflowcarddetail. insertrow (tblflowcarddetail. Rows. Length );
VaR Col = row. insertcell (0 );
Col. innerhtml = "<input readonly = \" True \ "maxlength = 6 size = 6 name = aimid> <input type = button value =... name = btnselectaimclient Index = \ "" + rowindex + "\" onclick = \ "selectaimclient (this. index) \ "> ";
Col = row. insertcell (1 );
Col. innerhtml = "<tr> <input id = aimname name = aimname size = 25 maxlength = 25 readonly = \" True \ "> ";
Col = row. insertcell (2 );
Col. innerhtml = "<input readonly = \" True \ "maxlength = 6 size = 6 name = itemno> <input type = button value =... name = btnselectitem Index = \ "" + rowindex + "\" onclick = \ "selectitem (this. index) \ "> ";
Col = row. insertcell (3 );
Col. innerhtml = "<input id = itemname name = itemname size = 25 maxlength = 25 readonly = \" True \ "> ";
Col = row. insertcell (4 );
Col. innerhtml = "<input id = spec name = spec size = 10 maxlength = 10 readonly = \" True \ "> ";
Col = row. insertcell (5 );
Col. innerhtml = "<input id = pattern name = pattern size = 10 maxlength = 10 readonly = \" True \ "> ";
Col = row. insertcell (6 );
Col. innerhtml = "<input id = unit name = unit size = 4 maxlength = 4 readonly = \" True \ "> ";
Col = row. insertcell (7 );
Col. innerhtml = "<input id = qty name = qty size = 6 maxlength = 6> ";
Col = row. insertcell (8 );
Col. innerhtml = "<input type = 'button 'value = 'delete' id = btndeleteline name = btndeleteline onclick = \" Return deleterow ('row "+ rowindex + "') \ "> </tr> ";
Rowindex ++;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.