dongsui5464 2014-08-19 20:20
浏览 79
已采纳

无法发布通过document.getElementById('div')。innerHTML返回的标记

I am working on this form with several select elements with options Yes, No or Not applicable. It was required that whenever the user select yes option a separate date field appears next to it. I used HTML DOM document.getElementById("id").innerHTML for this date field. Everything went well but I was not able to pass the value of date to the form action page using POST method. Check this code:

    <!-- javascript code -->  
  <script type="text/javascript">

function credit_check(name){
  if(name=='YES')document.getElementById('div2').innerHTML='Date: <input type="date" name="credit_check_date" value= "mm/dd/yyyy" />';
  else document.getElementById('div2').innerHTML='';
}
function employment_check(name){
  if(name=='YES')document.getElementById('div3').innerHTML='Date: <input type="date" name="employment_check_date" value= "mm/dd/yyyy" />';
  else document.getElementById('div3').innerHTML='';
}

</script>



</head>

<body>
<?php include("menu.inc"); ?>  
  <div id="main">

 <table>
<form method="post" action="checkinfo.php">  
       <tr><td colspan=2><hr/><input type="hidden" name="consultant_id" value="<?php echo $consult_id; ?>"> </td>

       </tr>

    <tr align="center">
    <td><b>Credit Check </b></td>
    <td>  
            <select name="2" onchange="credit_check(this.options[this.selectedIndex].value)">
            <option selected="selected">Please select ...</option>
                <option value="YES">Yes</option>
                <option value="NO">No</option>
                <option value="NA">Not Applicable</option>
            </select>
        </td>
        <td> <div id ="div2"> </div></td>
  </tr>

 <tr align="center">
    <td><b>Employment Check :<font color='red'>*</font></b></td>
    <td>  
            <select name="3" onchange="employment_check(this.options[this.selectedIndex].value)">
                <option selected="selected">Please select ...</option>
                <option value="YES">Yes</option>
                <option value="NO">No</option>
                <option value="NA">Not Applicable</option>
            </select>
        </td>
        <td> <div id ="div3"> </div></td>
    </tr>

    </form>
</table>
  • 写回答

3条回答 默认 最新

  • dongyue110702 2014-08-19 20:27
    关注

    Put the inputs into the HTML at loading, then simply hide/show them.

        <!-- javascript code -->  
      <script type="text/javascript">
    
    function credit_check(name){
      if(name=='YES')document.getElementById('div2').style.display = 'block';
      else document.getElementById('div2').style.display = 'none';
    }
    function employment_check(name){
      if(name=='YES')document.getElementById('div3').style.display = 'block';
      else document.getElementById('div3').style.display = 'none';
    }
    
    </script>
    
    
    
    </head>
    
    <body>
    <?php include("menu.inc"); ?>  
      <div id="main">
    
     <table>
    <form method="post" action="checkinfo.php">  
           <tr><td colspan=2><hr/><input type="hidden" name="consultant_id" value="<?php echo $consult_id; ?>"> </td>
    
           </tr>
    
        <tr align="center">
        <td><b>Credit Check </b></td>
        <td>  
                <select name="2" onchange="credit_check(this.options[this.selectedIndex].value)">
                <option selected="selected">Please select ...</option>
                    <option value="YES">Yes</option>
                    <option value="NO">No</option>
                    <option value="NA">Not Applicable</option>
                </select>
            </td>
            <td> <div id ="div2" style="display: none;"> 
                Date: <input type="date" name="credit_check_date" value= "mm/dd/yyyy" />
            </div></td>
      </tr>
    
     <tr align="center">
        <td><b>Employment Check :<font color='red'>*</font></b></td>
        <td>  
                <select name="3" onchange="employment_check(this.options[this.selectedIndex].value)">
                    <option selected="selected">Please select ...</option>
                    <option value="YES">Yes</option>
                    <option value="NO">No</option>
                    <option value="NA">Not Applicable</option>
                </select>
            </td>
            <td> <div id ="div3" style="display: none;"> 
                Date: <input type="date" name="employment_check_date" value= "mm/dd/yyyy" />
            </div></td>
        </tr>
    
        </form>
    </table>
    

    It's also a good idea to check out jQuery, it makes this kind of stuff a lot easier to do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥15 第一个已完成,求第二个做法
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?