How to Use js to obtain the textbox value in Asp.net. js cannot obtain the text value. [Asp.net getelementbyid usage]

Source: Internet
Author: User

(Reprinted) How to Use js to get the textbox value in Asp.net. js cannot get the text value

<Tr>
<TD class = "table_body" style = "width: 10%" align = "right">
Work Objectives
</TD>
<TD class = "table_none" style = "width: 90%" colspan = "2">
<Asp: textbox id = "txt_jobgoal" runat = "server" width = "100%" textmode = "multiline" tooltip = "Enter the work target! "> </ASP: textbox>
</TD>
</Tr>

 

// The javascript statement is as follows:

<Script language = "JavaScript" type = "text/JavaScript">

Function whetherempty ()
{
// Alert ("the KPI information cannot be blank! ");
Emptflag = false;
VaR jobgoal = Document. getelementbyid ("txt_jobgoal"). value;
}
</SCRIPT>

 

The value in the text control cannot be obtained! Set breakpoints. In The Real-Time Window, check that the value of document. getelementbyid ("txt_jobgoal") is null. When running, a message similar to the following is displayed: Document. getelementbyid () is not an object or the value is null!

Cause: the client ID is changed when textbox generates HTML. A lot of prefixes are added before txt_jobgoal.

 

Rewrite the JavaScript Functions on the page as follows:

<Script language = "JavaScript" type = "text/JavaScript">

Function whetherempty ()
{
// Alert ("the KPI information cannot be blank! ");
Emptflag = false;
VaR jobgoal = Document. getelementbyid ("<% = txt_jobgoal.clientid %>"). value;
}
</SCRIPT>

 

This article is from the csdn blog. For more information, see the source:Http://blog.csdn.net/sire168/archive/2010/06/22/5686041.aspx

(Reprinted) How to Use js to get the textbox value in Asp.net. js cannot get the text value

<Tr>
<TD class = "table_body" style = "width: 10%" align = "right">
Work Objectives
</TD>
<TD class = "table_none" style = "width: 90%" colspan = "2">
<Asp: textbox id = "txt_jobgoal" runat = "server" width = "100%" textmode = "multiline" tooltip = "Enter the work target! "> </ASP: textbox>
</TD>
</Tr>

 

// The javascript statement is as follows:

<Script language = "JavaScript" type = "text/JavaScript">

Function whetherempty ()
{
// Alert ("the KPI information cannot be blank! ");
Emptflag = false;
VaR jobgoal = Document. getelementbyid ("txt_jobgoal"). value;
}
</SCRIPT>

 

The value in the text control cannot be obtained! Set breakpoints. In The Real-Time Window, check that the value of document. getelementbyid ("txt_jobgoal") is null. When running, a message similar to the following is displayed: Document. getelementbyid () is not an object or the value is null!

Cause: the client ID is changed when textbox generates HTML. A lot of prefixes are added before txt_jobgoal.

 

Rewrite the JavaScript Functions on the page as follows:

<Script language = "JavaScript" type = "text/JavaScript">

Function whetherempty ()
{
// Alert ("the KPI information cannot be blank! ");
Emptflag = false;
VaR jobgoal = Document. getelementbyid ("<% = txt_jobgoal.clientid %>"). value;
}
</SCRIPT>

 

This article is from the csdn blog. For more information, see the source:Http://blog.csdn.net/sire168/archive/2010/06/22/5686041.aspx

Related Article

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.