Problem with select and hidden input

Hi,

I have an issue when submitting a form. The following are the relevant pieces of the form.

<?php $form = ActiveForm::begin([ 'enableClientValidation' => false ]); ?>

	<?php foreach ($modelDieDetailArray as $i => $modelDieDetail) : ?>

		<?= $form->field($modelDieDetail, "[$i]die_id")->widget(Select2::classname(), ['data' => ArrayHelper::map(Die::find()->all(), 'die_id', 'name'), 'options' => [ 'onchange' => 'load_die_data($(this).val(), '.$i.')' ] ])->label(false); ?>
		<?= $form->field($modelDieDetail, "[$i]main_die")->dropDownList([ '1' => 'Yes', '0' => 'No' ], [ 'disabled' => 'disabled', 'onchange' => '$("input:hidden#productionorderdie-'.$i.'-main_die").val($(this).val());' ])->label(false); ?>
		<?= $form->field($modelDieDetail, "[$i]main_die")->hiddenInput()->label(false) ?>

	<?php endforeach; ?>

<?php ActiveForm::end(); ?>

<?php
	function load_die_data(die_id, idx) {
	if (die_id == "") {
		$("#productionorderdie-"+idx+"-main_die").each(function () { $(this).val(""); });
		$("select#productionorderdie-"+idx+"-main_die").attr("disabled", "disabled");
	} else {
		$("select#productionorderdie-"+idx+"-main_die").removeAttr("disabled");
	}
}
?>

Where $modelDieDetailArray is an array of object of the ProductionOrderDie model class.

The issue is that when the form is submitted the main_die attribute is empty in the POST array ProductionOrderDie [].

Looks like this piece of jquery is not working:

$("input:hidden#productionorderdie-'.$i.'-main_die").val($(this).val());

I hope anyone can give me some lights on how to solve this.

Best regards,

isn’t it javascript? then why it’s wrapped with <?php ?> tags instead of <script> </script>?