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);
         });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?