How to read the values of HTML controls (such as text boxes)

Source: Internet
Author: User
1. Set the name attribute of the text box, for example, <input id = "text1" type = "text" name = "TXT"/>
2. Server Control (such as ASP: button) reading Method
(1) <asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>
(2) protected void button#click (Object sender, eventargs E)
{
String S = request ["TXT"]. tostring (); // here, TXT uses the name attribute of the text box.
Response. Write ("<SCRIPT> alert ('" + S + "') </SCRIPT> ");
}
3. How to read HTML controls (such as buttons)
(1) <input id = "button2" type = "button" value = "button" onclick = "Return button2_onclick ()"/>
(2) <SCRIPT type = "text/JScript">
Function button2_onclick (){
VaR OBJ = Document. getelementsbyname ("TXT"); // TXT uses the name attribute of the text box.
Alert (OBJ [0]. Value); // note that the object must contain a subscript.
Document. getelementbyid ("text1"). value = "ASD"; // text1 uses the ID attribute of the text box.
Document. All ["TXT"]. value = "ASD"; // TXT uses the name attribute of the text box.
}
</SCRIPT>

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.