Здравствуйте, мне нужно сделать смену второго параметра в зависимости от первого. Есть 5 типов ввода - text, image, textarea, ckeditor, checkbox
И в зависимости от выбранного типа ввода, выводить нужное поле - текстовое,поле загрузки и т.д.
Сделал вот так через show и hide, но получился большой одинаковый код
$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;
И формы
<div id="input" style="display:none;">
<?= $form->field($model, 'value')->textInput(); ?>
</div>
<div id="image" style="display:none;">
<?= $form->field($model, 'value')->fileInput(); ?>
</div> .....
Как можно по другому записать такой скрипт??
div#wrap
и просто в начале скрипта написать$('div#wrap > div').hide()
что спрячет все эти дивы с айдишниками а$('div#'+ selection).show()
покажет