How can I call a Javascript function from a hidden field?
<asp:HiddenField ID="hdnfield" onChange="callJsFunction()" runat="server" />
So what can replace onChange? because hiddenfield doesn't support onTextChanged...
How can I call a Javascript function from a hidden field?
<asp:HiddenField ID="hdnfield" onChange="callJsFunction()" runat="server" />
So what can replace onChange? because hiddenfield doesn't support onTextChanged...
why can not you use
$('#<% hdnfield.Id %>').change( function() { alert("Changed"); })
It's tricky to work with hidden fields. Try this listener i wrote. It worked for me in many different cases. I'm using jquery but you don't have to. This one is listening on value change but you can listen on any attribute.
Let say you have hidden input with some initial value:
<input id="change" type="hidden" value="SomeValue" />
Script below will check that value every 2 ses and alert for changes:
// Set empty global var for input value
inputValue = '';
listenOnChange = function() {
// Check for new value if any
checkForNewInputValue = $('#change').val();
if (inputValue == checkForNewInputValue) {
// Check after 2 sec for change
setTimeout("listenOnChange()",2000);
} else {
// Replace with new value
inputValue = checkForNewInputValue;
// Check after 2 sec for change
setTimeout("listenOnChange()",2000);
alert('IT WORKS');
}
}
$(document).ready(
inputValue = $('#change').val(), // Set Initial Value
listenOnChange() // Start listener
);
Button below will change that value. Copy, Paste and see how it works.
<button onclick="$('#change').val('1234566');">CHANGE</button>