JS get select change event

Source: Internet
Author: User

JS obtains the values before the select change event onchage and The onclick event.

<Select id = "wupin_id" name = "wupin_id" onclick = "savelast ()" onchange = "changeform (this. Value)">
<Option value = "0" selected> select the device type you want to use </option>
<Option value = "001"> HP scanner g5590 </option>
<Option value = "002"> HP scanner g2410 </option>
<Option value = "003"> HP scanner g3110 </option>
</SELECT>

<SCRIPT>
VaR lastindex, lastvalue;

Function savelast (){
VaR select = Document. getelementbyid ("wupin_id ");

Lastindex = select. selectedindex;
VaR midvalue = select. Options [lastindex]. value;
// Var text = select. Options [Index]. text;
If (midvalue! = "0 "){
Lastindex = select. selectedindex;
Lastvalue = select. Options [lastindex]. value;
}
}

Application:
Function changeform (VAL ){
VaR OBJ = Document. getelementbyid ("wupin_id ");
VaR tr01 = Document. getelementbyid ("tr01"). value;
VaR flag = Document. getelementbyid ("saverk"). Disabled;
VaR flag2 = Document. getelementbyid ("tr01"). Disabled;
If (Val! = "0" & flag2 = true ){
Document. getelementbyid ("tr01"). Disabled = false;
Document. getelementbyid ("tr01"). Focus ();
}
If (Val! = "0" & tr01! = "" & Flag! = True ){
Alert ("please save the data to the database first, and then scan and enter other types of items! ");
OBJ. Options [lastindex]. Selected = true; // load the user to change the previously selected value
Document. getelementbyid ("saverk"). Focus ();
}

}

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.