0
I am trying to hide and show fields based of the selection in a dropdown field. I got it do hide but when I select another value it doesn't display again.

<script type="text/javacript">
        function checkEm(){
            if (document.getElementById('JobTypeDDL').selected = "2"){
                document.getElementById('DateTbx').style.visibility = "hidden";
                document.getElementById('DateTbx').style.display = "none";
            } else {
                document.getElementById('DateTbx').style.visibility = "visible";
                document.getElementById('DateTbx').style.display = "block";
        }
    }
</script>

    <div class="InputField">
        <select name="JobTypeDDL" id="JobTypeDDL" onChange="checkEm()">
            <option value="0" <?php if ($_POST['JobTypeDDL'] == "0") {echo "selected='selected'";} ?> >Select Job Type</option>
            <option value="1" <?php if ($_POST['JobTypeDDL'] == "1") {echo "selected='selected'";} ?> >New Mobility</option>
            <option value="2" <?php if ($_POST['JobTypeDDL'] == "2") {echo "selected='selected'";} ?> >Service/Repair/Install</option>
        </select>
    </div>

<input name="DateTbx" id="DateTbx" type="text" <?php if (!$_POST['DateTbx'] == "") {echo "value='". $_POST['DateTbx']."'";} ?> />
4

2 回答 2

0

在 if 条件下,您使用单个 =。改为使用 ===

于 2013-01-29T23:27:37.110 回答
0

用于测试语句==中的相等性。if您正在使用=,这是分配。

于 2013-01-29T23:24:59.263 回答