i want change price on the fly. but this do not work.
Jquery$('input[name ="pricehidden'"]').val(parseInt($('input[name ="pricehidden'"]').val()) + 100);
HTML

$form['hiddenprice'] = array(
				'#type' => 'hidden',
				'#value' => 20,
                                                   );

i use alert($('input[name="pricehidden"]').val()),it shows the result 120.
but form_state['values']['hiddenprice'] result still 20.

can somebody help me.

Comments

yictory’s picture

I use $_POST['hiddenprice'] instead $form_state['values']['hiddenprice'],the problem solved.but i still want to know,why $form_state do not work?
-----------------------------
www.linellae.com

infojunkie’s picture

Same thing happens to me.

infojunkie’s picture

In the hidden control $form entry, set '#default_value' instead of '#value' :-)

pownraj’s picture

#default_value fixed it :)

N1ghteyes’s picture

Just to confirm here, setting a hidden field with '#value' means that it cannot be modified on form submission.

If you want to modify the value of the hidden field, you need to use '#default_value', docs link:

https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...

Note that if you plan to use JavaScript to change your hidden element's value, you will need to use the #default_value property rather than #value.

nDigitHQ’s picture

Realize this is old but..

Should mention as well that if you're still noticing a problem after using #default_value, it's likely that you just need to cast the value as a string. Take this for example:

$("a").click(function(e) {
    e.preventDefault();
		
    //Update the hidden variable
    var type = $(this).attr("data-type");
    $("input[name='type']").val(String(type));
});