<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body onload="addOptionAll()";> <form name="frmMain" action="" method="post"> <script language="JavaScript"> function addNewOptions(selectbox,text,value) { var optn = document.createElement("option"); optn.text = text; optn.value = value; selectbox.options.add(optn); } function addOptionAll(selectbox){ addNewOptions(document.frmMain.ddlSelect, "Green","Green"); addNewOptions(document.frmMain.ddlSelect, "Red","Red"); addNewOptions(document.frmMain.ddlSelect, "Pink","Pink"); addNewOptions(document.frmMain.ddlSelect, "Orange","Orange"); } function RemoveAllOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--) { selectbox.remove(i); } } function RemoveOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--) { if(selectbox.options[i].selected) selectbox.remove(i); } } </script> <select id="ddlSelect" name="ddlSelect" size="6" multiple></select> <br> <input type="button" onClick="RemoveOptions(frmMain.ddlSelect)"; value='Remove Selected'> <input type="button" onClick="RemoveAllOptions(frmMain.ddlSelect)"; value='Remove All'> <input type="button" onClick="addOptionAll()"; value='Add All'> <br>Add New Item<br> Value <input type="text" name="txtValue" value=""> Text <input type="text" name="txtText" value=""> <input type="button" onClick="addNewOptions(frmMain.ddlSelect,frmMain.txtText.value,document.frmMain.txtValue.value)"; value='Add'> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท