Heidi Anselstetter
Heidi Anselstetter

Reputation: 31

jquery: How can I select a hidden field?

I am using the jquery.raty script which does write a hidden field into my page like:

<input id="cancel-score" type="hidden" name="news_question_1" value="1">

I have this and many other form elements which I would like to monitor onChange.

I do this with:

$('#NewsletterSurveyForm').find(':input').each(function(){
        $(this).change(function(){....

Which works for all elements, but just not the hidden one.

Does anyone has an idea how to get its value?

Upvotes: 3

Views: 12424

Answers (2)

Chamika Sandamal
Chamika Sandamal

Reputation: 24312

you can use following code,

$("input[type='hidden']").change(function(){......});

but change event doesn't fire when the value is programmatically changed. so you have to trigger it manually when the value changes.

$("#hiddenId").val("new value").change();

Upvotes: 8

Christian Dalager
Christian Dalager

Reputation: 6643

I don't think the hidden input supports the change event.

See this question

I think you should address this change trigger a level higher up.

Upvotes: 1

Related Questions