Js for Select

Source: Internet
Author: User


1) var obj;
Obj = document. getElementById ("Card"); // obtain the tag Id
Index = obj. selectedIndex; // select an index
Value = obj. options [index]. value; // select the value.
Text = obj. options [index]. text; // select the text value.


2) Add a new row
AddSelectEmptyAndValueOption (obj, value, text );
Function addSelectEmptyAndValueOption (select, value, value2 ){
Var option = document. createElement ("option ");
Option. value = value;
Option. innerHTML = value2;
Select. appendChild (option );
}
 
3) $ ('# selectid'). empty (); // clear data


4) Select the default value for province, city, and district linkages
Function refreshResult (s ){
Var obj;
Var str;
Var I;
If (s = "1 "){
Obj = document. getElementById ("province ");
Str = '<% = deliveryprovince %> ';
For (I = 0; I <obj. length; I ++ ){
If (obj [I]. text = str ){
Obj [I]. selected = true;
ShowAreaInfo (obj [I]. value, "city ");
RefreshResult ("2 ");
}
}
} Else if (s = "2 "){
Obj = document. getElementById ("city ");
Str = '<% = deliverycity %> ';
For (I = 0; I <obj. length; I ++ ){
If (obj [I]. text = str ){
Obj [I]. selected = true;
ShowAreaInfo (obj [I]. value, "county ");
RefreshResult ("3 ");
}
}
} Else if (s = "3 "){
Obj = document. getElementById ("county ");
Str = '<% = deliveryarea %> ';
For (I = 0; I <obj. length; I ++ ){
If (obj [I]. text = str ){
Obj [I]. selected = true;
}
}


}
}


5) dynamically Add a new row of data to the table
Function insertRow2 (MaterialCode, MaterialName, Weight, UnitName, RetailPrice, InvQty, I ){
Var lb1Name = "lbName" + I; // full name of the product
Var lb1Price = "lbPrice" + I; // price
Var lbWeight = "lbWeight" + I; // Specification
Var lbInvQty = "lbInvQty" + I; // inventory
$ ("# ShopInvInfo"). append ("<tr>" +
'<Td width = 100> <label id =' + lb1Name + '>' + MaterialName + '</label> </td>' +
'<Td width = 100> (<label id =' + lbWeight + '>' + Weight + ''+ UnitName + '</label>) </td>' +
'<Td width = 100> (<label id =' + lb1Price + '>' + RetailPrice + 'RMB </label>) </td>' +
'<Td width = 100> stock preparation: <label id =' + lbInvQty + '>' + InvQty + '</label> </td>' +
"</Tr> ");
}


Author: loveheronly

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.