I have usercontrol with some server and client controls. I am trying to add values from text box to list box using jquery (on button click event) but getting following error;
Microsoft JScript runtime error: Syntax error, unrecognized expression: #<%= txtSubVendorRef.ClientID %>
ascx file;
<tr>
<td>
<asp:TextBox ID="txtSubVendorRef" TabIndex="34" MaxLength="32" runat="server"
Width="220"></asp:TextBox>
</td>
<td valign="top">Visit Dates</td>
<td>
<input type="button" id="btnAddRef" name="filter" value="Filter" />
</td>
<td>
<asp:ListBox runat="server" ID="lstVisitDates" Width="220px"></asp:ListBox>
</td>
</tr>
Here is the jquery function in js file;
$("#btnAddRef").click(function () {
var txt = $("#<%=txtSubVendorRef.ClientID%>");
var svc = $(txt).val(); //Its Let you know the textbox's value
var lst = $('#<%= lstVisitDates.ClientID %>');
var options = $('#<%= lstVisitDates.ClientID %> option');
var alreadyExist = false;
$(options).each(function () {
if ($(this).val() == svc) {
alert("Item alread exists");
alreadyExist = true;
return;
}
txt.val("");
// alert($(this).val());
});
if (!alreadyExist)
$(lst).append('<option value="' + svc + '">' + svc + '</option>');
return false; });