Use javascript dynamic Insert delete input box in JSP implement code _javascript skill

Source: Internet
Author: User
JavaScript code:
Copy Code code as follows:

<script language= "JavaScript" >
function Addrows () {
var len = optionlist.rows.length; Get the number of rows in a table
var obj = Optionlist.insertrow (len);//insert on last line
/** inserts the first column **/
Obj.insertcell (0);
Obj.cells (0). innerhtml= "Options" + (len+1) + ": <input type=text name=option";
}
function DeleteRow () {
var len = optionlist.rows.length;
if (len <= 1) {
Alert ("Must have at least one option");
}
else {
Optionlist.deleterow (len-1);//Delete last item
}
}
function Getoptioncount () {
return optionlist.rows.length;
}
</script>

Key code in a JSP page
Copy Code code as follows:

<input type= "button" id= "BT1" value= "add Option" onclick= "addrows ();" >
<input type= "button" id= "BT2" value= "delete option" onclick= "deleterow ();" >

Set the ID of the table so that the table can be recognized in JavaScript
Copy Code code as follows:

<table id= "Optionlist" >
</table>
Related Article

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.