Javascript not reading value from hidden textBox - JQuery C#
- by Paul van Valkenburgh
I'm a non-specialist with JavaScript / JQuery and I'm having trouble figuring out why my script doesn't work. When my C# page loads, I have a hidden textBox txtHiddenKeywordArray which gets dynamically filled with comma separated values like... horse, buggy, track
I'm trying to use the highlight functionality in jquery.highlight-3.js where I have a label text field that will contain and highlight the words in the keywords list. I'm using the script
<script language="javascript" type="text/javascript">
var myString = document.getElementById('<%=txtHiddenKeywordArray.ClientID%>').val()
myArray = myString.split(" ");
$(document).ready(function () {
for (i = 0; i < myArray.length; i++)
$("p").highlight(myArray[i])
});
</script>
Here is the textBox declaration :
<asp:TextBox ID="txtHiddenKeywordArray" ClientIDMode="Static" runat="server" Visible="false"></asp:TextBox>
It worked great when I hard coded the values of var myString. I've tried researching it and keep seeing the same example of the way I have it done. The page does use a MasterPage. Could this affect it?
Any idea how I can get the script to see the values from the textbox? Do I need a RegisterStartUpScript or something? Thanks for any help you can provide.