views:

94

answers:

3

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="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>
+1  A: 

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

Kaleb Brasee
because I am running a $.GetJSON command, and the onchange function gets fired before the results come in ;(
Grayson Mitchell
+2  A: 

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

griegs
ok, this is what I have tried... does not work. (have edited my post above)
Grayson Mitchell
cool, so basically the solution is that after I update a field with javascript, I need to run the .change() command...
Grayson Mitchell
A: 

There is no difference between hidden fields and normal inputs.

ali62b