Add, modify, and delete option elements in Firefox and Opera,select compatible

Source: Internet
Author: User

Add, modify, and delete option elements in Firefox and Opera,select compatible with the following code:

function Watch_ini () {//Initial
for (var i=0; i<arguments.length; i++) {
var ooption=new option (Arguments[i],arguments[i]);
document.getElementById ("Myselect"). Options[i]=ooption;
}
}
function Watch_add (f) {//Increase
var ooption=new option (F.word.value,f.word.value);
F.keywords.options[f.keywords.length]=ooption;
}


Frequently used about select option Operations

Create an Option Object

function createoption () {
var random = Math.floor (Math.random () *9000) +1000;
return new option (RANDOM,RANDOM);
}

Deletes an option specified in the Options collection

function Removeoption (index) {
if (index >= 0) {
Colls.remove (index);
Lastoptiononfocus (colls.length-1);
}
Watchstate ();
}

Gets the currently selected option index

function Getselectedindex () {
return selecttag.selectedindex;
}

Get the total number of options collections

function Getoptionlength () {
return colls.length;
}


Gets the currently selected option text

function Getcurrentoptionvalue (index) {
if (index >= 0)
Return Colls (index). value;
}


Gets the currently selected option value

function Getcurrentoptiontext (index) {
if (index >= 0)
Return Colls (index). text;
}


Use the last item in the options collection to get focus

function Lastoptiononfocus (index) {
Selecttag.selectedindex = index;
}

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.