douzuqin3467 2012-10-20 20:46
浏览 45

如何在以下情况下禁用输入类型=文本

I've got the following table which is build for every guest entry in a MySQL table.

    echo '<tr>
            <td>'.$gastId[$i]." ".$voornaam[$i].'</td>
            <td><input type="radio" name=present'.$gastId[$i].'[] value=1 onclick="setReadOnly(this)" checked></td>
            <td><input type="radio" name=present'.$gastId[$i].'[] value=2 onclick="setReadOnly(this)"></td>
            <td><input type="text"  name="artiest[]" value="'.$artiest[$i].'"></td>
            <td><input type="text"  name="titel[]" value="'.$titel[$i].'"></td>
        </tr>';

I would like to disable the two fields artiest (artist) and titel (title) base on the radio button present'.$gastId[$i].

I was trying to solve it with javascript, but I have little experience with javascript. Is there a way link the radio buttons and text field per row by ID or something?

<script language='javascript'>
<!-- //
function setReadOnly(obj)
{
    if(obj.value == 1)
    {
        document.forms[0].artiest.readOnly = 0;
    } else {
        document.forms[0].artiest.readOnly = 1;
    }
}
// -->
</script>

Thank you very much for your help!

EDIT 21-10-2012

Sorry I've should have been more clear.

If the table looks like this:

------------------------------------------------
|  P  |  NP  | Artist        | Title           |
------------------------------------------------
|  X  |      | Enabled       | Enabled         |
------------------------------------------------
|     |  X   | Disabled      | Disabled        |
------------------------------------------------
etc

So the radio button of that row controls if the fields in that same row are enabled or disabled.

  • 写回答

2条回答 默认 最新

  • dream890110 2012-10-20 20:55
    关注

    just add ID to :

    <td><input type="text"  id="artiest" name="artiest[]" value="'.$artiest[$i].'"></td>
                            ^^^^^^^^^^^
    
    评论

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码