PHP - Select yes or no, yes causes a new input to appear

前端 未结 1 826
走了就别回头了
走了就别回头了 2021-01-28 18:31

I\'m not sure if this is possible or where to start to tackle it with, but I\'m wanting to create a select with a yes or no option, which if yes is selected (form is yet to be s

相关标签:
1条回答
  • 2021-01-28 18:59

    I like JavaScript for that kind of stuff, personally.

    <select name="retrieveMarriage" id="retrieveMarriage" onblur="myFunction()">
            <option value='' disabled selected style='display:none;'>Are you married?</option>
            <option value="Yes">yes</option>
            <option value="No">no</option>
    </select>
    <span id="newDate"></span>
    

    And the JavaScript:

    function myFunction(){
      var x=document.getElementById('retrieveMarriage').value;
      if(x == 'yes'){
         document.getElementById('newDate').innerHTML='<input type=text id="myNewField"/>';
         Whatever else you want to do...
      }
    }
    
    0 讨论(0)
提交回复
热议问题