开发者

How to pass textbox value to java script on button click event [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How to pass text in a textbox to javascript function?

I need t开发者_开发知识库o pass the text box value as parameter of javascript method which will be fired on button click.

<asp:TextBox ID="rowID" runat="server"> </asp:TextBox>
        <asp:Button runat="server" ID="Click" OnClientClick="PassValue(Textboxvaluehere)"/>

PassValue is JavaScript method.

Thanks in Advance.


<asp:TextBox ID="rowID" runat="server"> </asp:TextBox>
<asp:Button runat="server" ID="Click" OnClientClick="GetTextBoxValue('<%= rowID.ClientID %>')"/>



function GetTextBoxValue(textBoxID){
   var value = window.document.getElementById(textBoxID).value; }


Or for cleaner mark-up, bind the event in code-behind at PageLoad like this

if (!IsPostBack)
{
    string script = String.Format("GetTextBoxValue('{0}')", rowID.ClientID);
    Click.Attributes.Add("onclick", script);
}

Now your mark-up can be like this.

<asp:TextBox ID="rowID" runat="server"> </asp:TextBox>
<asp:Button ID="Click" runat="server" />


<asp:Button runat="server" ID="Click" OnClientClick="GetTextBoxValue('<%= rowID.ClientID %>'.value)"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜