doudilin1225 2017-01-19 14:11
浏览 75
已采纳

勾选复选框时启用文本框 - php

I am trying to enable the textbox when checkbox is checked and my coding do like what I want. When submit button clicked it will check the entire form and give error information for every empty field that not been filled and keep the rest information remain to every field that been filled. The problem is, when the checkbox is checked, textbox enabled and been filled, after pressing the submit button (when all required field not completed), the textbox will become disabled with value remained.

Below is coding that I currently use :

<input type="checkbox" name="chklist" onchange="document.getElementById('txtOthers').disabled = !this.checked;" <?php if(isset($_POST['btnSubmit']) && isset($_POST['chklist'])) echo "checked" ?> /> OTHERS : 
    <input style="width: 130px;" type="textbox" id="txtOthers" name="txtOthers" disabled value="<?php echo $others;?>" />
  • 写回答

1条回答 默认 最新

  • dsg56465 2017-01-19 14:51
    关注

    You can use jQuery to do so :

    <input type="checkbox" name="chklist" id="checkbox" <?php if(isset($_POST['btnSubmit']) && isset($_POST['chklist'])) echo "checked" ?> /> OTHERS : 
    <input style="width: 130px;" type="textbox" id="txtOthers" name="txtOthers" disabled value="<?php echo $others;?>" />
    
    $(document).ready(function(){
        $("#checkbox").change(function(){
            if ($('input.checkbox_check').is(':checked')) {
               $(#txtOthers).show();
            }else{
               $(#txtOthers).hide();
            }
        });
        $("form").submit(function() {
            $("#txtOthers").prop('disabled', true);
         });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。