How to pass textbox value to java script on button click event [duplicate]
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)"/>
精彩评论