Hello, I need to change the second parameter depending on the first one. There are 5 input types - text, image, textarea, ckeditor, checkbox
And depending on the selected input type, display the required field - text, download field, etc.
I did it like this through show and hide, but it turned out to be a big identical code
$script = <<< JS $('.js-type').on('change',function(){ var selection = $(this).val(); switch(selection){ case "image": $("#image").show() $("#input").hide() $("#textarea").hide() $("#fck").hide() $("#checkbox").hide() break; case "input": $("#input").show() $("#image").hide() $("#textarea").hide() $("#fck").hide() $("#checkbox").hide() break; case "textarea": $("#textarea").show() $("#image").hide() $("#input").hide() $("#fck").hide() $("#checkbox").hide() break; case "fck": $("#fck").show() $("#textarea").hide() $("#image").hide() $("#input").hide() $("#checkbox").hide() break; case "checkbox": $("#checkbox").show() $("#image").hide() $("#textarea").hide() $("#fck").hide() $("#input").hide() break; } }); JS; And forms
<div id="input" style="display:none;"> <?= $form->field($model, 'value')->textInput(); ?> </div> <div id="image" style="display:none;"> <?= $form->field($model, 'value')->fileInput(); ?> </div> ..... How can another script be written ??
div#wrapand just at the beginning of the script write$('div#wrap > div').hide()which will hide all these divs with id and$('div#'+ selection).show()will show - Alexey Shimansky