search

Home  >  Q&A  >  body text

How to clear input field after radio button click?

<p>After clicking "Select number of tweets from date", the "Select end date" input field must be removed. Can anyone help me? This is the code: </p> <p> <pre class="brush:js;toolbar:false;">function yesnoCheck() { if (document.getElementById('yesCheck').checked) { document.getElementById('ifYes').style.display = 'block'; } else document.getElementById('ifYes').style.display = 'none'; }</pre> <pre class="brush:html;toolbar:false;"><form> <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="noCheck">Select date range <br> <br> <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="yesCheck">Select number of tweets from date<br><br> <div id="ifYes" style="display:none"> Desired number of tweets <input type="number" min="1" max="20" id='yes' name='yes'><br> </div> <br> <img src="icon2.png"><label for="date">Select start date:</label><br> <input type="datetime-local" id="Test_DatetimeLocal"><br><br> <img src="icon2.png"><label for="date">Select end date:</label><br> <input type="datetime-local" id="Test_DatetimeLocal"><br><br> <input type="submit" value="submit" class="submit"> </form></pre> </p>
P粉396248578P粉396248578457 days ago560

reply all(1)I'll reply

  • P粉327903045

    P粉3279030452023-09-03 00:48:53

    Follow your #ifYes tags. Wrap the input and label with div, assign it an id, and then just use document.getElementById('select-end-period').style.display = 'none';

    function yesnoCheck() {
      if (document.getElementById('yesCheck').checked) {
        document.getElementById('ifYes').style.display = 'block';
        document.getElementById('select-end-period').style.display = 'none';
    
      } else {
        document.getElementById('ifYes').style.display = 'none';
        document.getElementById('select-end-period').style.display = 'block';
      }
    }
    <form>
      <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="noCheck">选择期间 <br>
      <br>
      <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="yesCheck">从日期开始的推文数量<br><br>
      <div id="ifYes" style="display:none">
        期望推文数量 <input type="number" min="1" max="20" id='yes' name='yes'><br>
      </div>
    
    
      <br>
      <img src="icon2.png"><label for="date">选择开始日期:</label><br>
      <input type="datetime-local" id="Test_DatetimeLocal"><br><br>
      <div id="select-end-period">
        <img src="icon2.png"><label for="date">选择结束日期:</label><br>
        <input type="datetime-local" id="Test_DatetimeLocal"><br><br>
      </div>
      <input type="submit" value="提交" class="submit">
    </form>

    reply
    0
  • Cancelreply