set value input hidden code example

Example 1: javascript change hidden input value

document.getElementById("myHiddenInputID").value = "MyNewValue";

Example 2: onchange value in hidden input

//in the HTML: <input id="myValue" type="hidden" name="myValue" value="">
$(function(){
    var $hello= $('[id$="myValue"]');

    $hello.on("change", function(){ //bind() for older jquery version
        alert('hey');
    }).triggerHandler('change'); //could be change() or trigger('change')
});

//Then, each time you change the value of targeted hidden inputs, trigger handler, e.g:
$('#myValue').val('the new value').triggerHandler('change');
//That's because onchange event is not fired automatically changing its value programatically.