简体   繁体   中英

Pass value of textarea when submit button is clicked

<textarea id="Comment" type="text" runat="server" rows="7" 
maxlength="2000" />

<input id="SubmitComment" type="button" value="Submit"
onclick="SubmitButton()" /> 

When the user enters data into the textarea and clicks the 'Submit' button I want the data to be passed to the submitButton() where I can then send it on to Functions.CommentBoxForInvoiceUpdates

function SubmitButton() {
var commentBoxData = $('#Comment').val();
Functions.CommentBoxForInvoiceUpdates(id, Labour, commentBoxData);
        } 

Id and Labour are defined earlier so they work fine, 'CommentBoxData' however is showing up as undefined when I run it through a break point. Any why the data in the comment box is being sent through when submit is clicked?

Thanks for any ideas

You tagged with asp.net. Sure you are using the rendered IDs?

尝试

var commentBoxData = $('#<%=Comment.ClientID%>').val();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM