开发者

How tell when a hidden field is changed

I have some javascript I want to run when a hidden field is changed (via javascript) Is there any way to do this? (or anyway at all to have a field that is not "visible" in asp mvc that I can get a change event on)

NOTE: I have confirmed that it is not the fact that the field that is hidden that is the problem, but the fact the field is updated with javascript! The change event does not fire when I update a field with javascript.

Edited

To Clarify this works:

//set up change event
$('#154').change(function() {
ScoringDerivation(154, 6,162,165);;                                                             
                        });

<select id="154" name="154"><option value="">&lt;Select&gt;</option>
<option value="6001">Good</option>
<option value="6002">Average</option>
<option value开发者_JAVA技巧="6003">Poor</option>
<option selected="selected" value="6004">No Match</option>
</select>

But this does not:

//set up change event
$('#165').change(function() {
    DerivationAdd3(165,166,167,226);; 
});


<input id="165" name="165" type="hidden" value="0" /><label id="165Label" name="165Label">0</label>


Use jQuery to do the checking.

$('#FieldId').change( function() { alert(9); })

it could be onchange or changed. untested but i use similar.

google jQuery;

actually, here is the source you need i think. change()-jQuery


If you're running Javascript to change the hidden field, why not just have that Javascript call the desired onchange function?


I had this problem and couldn't fire the change event since I can't modify the code that's actually setting the field. So here's what I did:

var file = $("#hidden_field_id");
var previous_value = file.attr("defaultValue");
var interval = setInterval(function(){
    if(previous_value != file.val()){
    fire_change_event(previous_value, file.val());
    previous_value = file.val();
    }
}, 50);
$(window).unload(function(){clearInterval(interval);});

This seemed to work in the 3 minutes of testing I did;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜