Just two switches:

<input type="radio" name="r" value="1" onclick="check()">Даты неизвестны<br> <input type="radio" name="r" value="2" onclick="check()"><span>Даты известны<span> <div id="div1"></div> 

By default, nothing is selected, when we select the second one, then we add input fields (up to here did it ourselves):

 function check() { var inp = document.getElementsByName('r'); for (var i = 0; i < inp.length; i++) { if (inp[i].type == "radio" && inp[i].checked) { if (inp[i].value == 1) { document.getElementsByName('text1').disabled = true; } if (inp[i].value == 2) { document.getElementById('div1').innerHTML = '<input type="date" name="d1" ><input type="date" name="d2" >'; } } } } 

But "type was wrong and change the choice" - the added field does not disappear. An attempt to make it inactive does not lead to anything (this is enough). How to get html from js ? How to remove added "by mistake" field?

jsfiddle link

    2 answers 2

    The error is that in the html code there are no elements with the name 'text1'. In addition, the code:

     document.getElementsByName('text1') 

    returns an array of elements and the array obviously does not have the property "disabled".

    And as noted above, the input is sufficient to make it initially hidden.

    Example with hide / close: http://jsfiddle.net/gbcx09tp/1/

    • the element was - the result did not change (.. (yes, I am very poor at JS), and how to make the display: none entries lay as it should be in css? (if you switch to id, you probably just changing them , you should be able to contact them ... but here is the name) - Shilgen
    • Create 2 classes: .hide {display: none; } .show {display: block; } Initially, diva is registering a hide class: <div id = "div1" class = "hide"> In the handler you change classes: document.getElementById ("div1"). ClassName = 'show' document.getElementById ("div1"). ClassName = 'hide' Updated example: jsfiddle.net/gbcx09tp/4 - evz

    Changed your code. https://jsfiddle.net/shilgen/egL035xg/1/ You can omit the element div1 every time, but simply make them hidden initially, and then show / hide.