Jiju John
Jiju John

Reputation: 821

Reset hidden value of a form in mvc using jQuery

I have two forms in a single view and when clicking on a button outside the forms I use jQuery to submit the form based on selection, and I need to pass a value to controller.

I am adding hidden field using below code to a form

$('#myform').append("<input type='hidden' name='option' value='myval' />");

How do I clear and reassign value to this hidden field using jQuery for each submit?

Upvotes: 0

Views: 446

Answers (1)

Calos
Calos

Reputation: 1942

Assign a id for this element:

$('#myform').append('<input type="hidden" id="my-id" name="option" value="myval" />');

Use id selector to assign new value.

$('#myform #my-id').val('new val');

By the way, your append string have syntax error (quotes)

Upvotes: 1

Related Questions