JS obtains the values of the Asp.net server-side controls label, Textbox, radiobuttonlist, and dropdownlist.

Source: Internet
Author: User

When working on BS architecture projects, we often encounter the need to use js to call the Asp.net server-side control value.

The value of most controls can be obtained by calling its value attribute in JS, but there are exceptions.

Label controls are commonly used. The value cannot be obtained through the value attribute in Js.

Example obtained by label control JS, VAR text = Document. getelementbyid ('label1'). innertext;

If var text = Document. getelementbyid ('label1'). value; then text is undefined.

The textbox Value

VaR text = Document. getelementbyid ('textbox 1'). value;

For radiobuttonlist and dropdownlist, their acquisition methods are quite different! This is mainly because they generate different HTML elements.

The value of dropdownlist is relatively simple:

VaR ddlvalue = Document. getelementbyid ('ctl00 _ contentplaceholder3_ddlfolws '). value;

However, obtaining the value of radiobuttonlist is troublesome:

VaR value = "";

var result = document. getelementsbyname ('ctl00 $ contentplaceholder3 $ rblresult');
for (VAR I = 0; I If (result. item (I ). checked) {
value = result. item (I ). value;
}< BR style = "line-Height: 10px;" >}

If no value is selected for the radiobuttonlist control, the value is blank!

====== Substring usage (string truncation) ======

function substringdemo () {
var SS; // declare a variable.
var S = "The rain in Spain falls mainly in the plain .. ";
SS = S. substring (12, 17); // obtain the substring.
return (SS); // returns a substring.
}

 

From: http://kb.cnblogs.com/a/2288883/

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.