При нажатии не открываю блоки

310
13 января 2017, 07:41

Здравствуйте! Написал две функции появления и исчезновения блоков, но они почему-то не открываются. При клике просто ничего не происходит. В чём проблема кода? Почему оно не открывает блоки?

HTML:

<div class="radio">
   <label><input onclick="hide(full)" id="full" type="radio" checked name="family" value="Полная"/>Полная<br/></label>
   <label><input onclick="show(notfull)" id="notfull" type="radio" name="family" value="Неполная"/>Неполная<br/></label>
</div>
<div class="field" id="second" style="display:none;">
   <div id="family">
      <label><input type="radio" name="how1" value="Студент без матери."/>Студент без матери.<br/></label>
      <label><input type="radio" name="how1" value="Студент без отца."/>Студент без отца.<br/></label>
      <label><input type="radio" name="how1" value="Мать-одиночка."/>Мать-одиночка.<br/></label>
      <label><input type="radio" name="how1" value="Родители разведены."/>Родители разведены.<br/></label><br/>
   </div>
</div>

JS:

var mest=document.getElementById('mest');
var inog=document.getElementById('inog');
var full=document.getElementById('full');
var notFull=document.getElementById('notfull');
var first=document.getElementById('first');
var second=document.getElementById('second');
function hide(a) {
   if(a==mest){
      first.style.display="none";
   }
   if(a==full){
      second.style.display="none";
   }
};
function show(a) {
   if(a==inog){
      first.style.display="block";
   }
   if(a==notfull){
      second.style.display="block";
   }
};
Answer 1

У вас переменные не взяты в кавычки.

Исправленный код:

HTML:

<div class="radio">
   <label><input onclick="hide('full')" id="full" type="radio" checked name="family" value="Полная"/>Полная<br/></label>
   <label><input onclick="show('notfull')" id="notfull" type="radio" name="family" value="Неполная"/>Неполная<br/></label>
</div>
<div class="field" id="second" style="display:none;">
   <div id="family">
      <label><input type="radio" name="how1" value="Студент без матери."/>Студент без матери.<br/></label>
      <label><input type="radio" name="how1" value="Студент без отца."/>Студент без отца.<br/></label>
      <label><input type="radio" name="how1" value="Мать-одиночка."/>Мать-одиночка.<br/></label>
      <label><input type="radio" name="how1" value="Родители разведены."/>Родители разведены.<br/></label><br/>
   </div>
</div>

JS:

var mest=document.getElementById('mest');
var inog=document.getElementById('inog');
var full=document.getElementById('full');
var notFull=document.getElementById('notfull');
var first=document.getElementById('first');
var second=document.getElementById('second');
function hide(a) {
    if(a == 'mest'){
        first.style.display="none";
    }
    if(a == 'full'){
        second.style.display="none";
    }
};
function show(a) {
    if(a == 'inog'){
        first.style.display="block";
    }
    if(a == 'notfull'){
        second.style.display="block";
    }
};
READ ALSO
Поиск наставника [требует правки]

Поиск наставника [требует правки]

Доброго времени сутокИщу наставника в области верстки

347
Bootstrap - проблема с шаблоном Cover

Bootstrap - проблема с шаблоном Cover

Столкнулся со странной проблемой, работая с Bootstrap

457
Как сделать &ldquo;гамбургер-меню&rdquo;

Как сделать “гамбургер-меню”

Доброго времени суток! Пытаюсь научиться делать гамбургер-меню, да не получается

494
Ограниченный доступ к веб-виджету

Ограниченный доступ к веб-виджету

Всем приветУ меня есть сайт-сервис с большой базой данных по узкой тематике (скажем, астрономия)

378