PHP - WebCalendar - 根据下拉列表选择隐藏字段

时间:2011-10-28 14:58:41

标签: php javascript jquery html css

使用WebCalendar应用http://www.k5n.us/webcalendar.php,我正在为额外字段的工作方式创建一些自定义修改。

特别是,我创建了两个额外的字段;其中一个是县的下拉列表,另一个是文本字段。下拉列表中的一个选项是**OTHER,文本字段可供用户指定其**OTHER选项。

我可以使用以下命令在PHP中指定下拉列表和选择:

if ($site_extras[1][3] == '**OTHER' )
  { do something to hide html class .other_field }

根据下拉列表输入隐藏/显示文本字段的方向有任何提示或推动吗?

请根据需要编辑和删除/添加标签。我只是选择了可能与此操作的需要相关的那些。

编辑:Html代码段

<table class="extra_table" summary="">
            <tr>
              <td class="aligntop bold">*Location:</td>
              <td class="extra_field_input">
                <select name="County">
                  <option value="Select County...
"  selected="selected">Select County...

</option>
                  <option value="DODGE" >DODGE
</option>
                  <option value="DOUGLAS" >DOUGLAS
</option>
                  <option value="LANCASTER" >LANCASTER
</option>
                  <option value="MADISON" >MADISON
</option>
                  <option value="**OTHER" >**OTHER
</option>
                  <option value="--------------------" >--------------------

</option>
                  </select>

                </td>
              </tr>
            <tr>
              <td class="aligntop bold">**If Other, Please Specify:</td>
              <td class="extra_field_input">
                <input type="text" size="17" name="Other_County" value="" />
                </td>
              </tr>

1 个答案:

答案 0 :(得分:1)

看看这个jsfiddle:http://jsfiddle.net/2bt8D/

我必须在您的文本字段中添加一个额外的类以区分它extra,并将您的输入/文本字段设置为style="display:none;"以启动。如果可以在您使用的框架的限制范围内进行,那么您就是胜利者。 (注意:有更好的方法来编写Jquery!)

Jquery声明:

$(function() {
    $("select").change(function() {        
        var selectValue = $(".extra_field_input select").val();

        if (selectValue == "**OTHER") {
            $(".extra_field_input input").show();
            $(".extra").show();
        } else {
            $(".extra_field_input input").hide();
            $(".extra").hide();
        };
    });
});

需要HTML

<table class="extra_table" summary="">
<tr>
    <td class="aligntop bold">*Location:</td>
    <td class="extra_field_input">
         <select name="County">
              <option value="Select County..." selected="selected">Select County...</option>
              <option value="DODGE" >DODGE</option>
              <option value="DOUGLAS" >DOUGLAS</option>
              <option value="LANCASTER" >LANCASTER</option>
              <option value="MADISON" >MADISON</option>
              <option value="**OTHER">**OTHER</option>
         </select>
    </td>
</tr>
<tr>    
    <td class="aligntop bold extra" style="display:none;">**If Other, Please Specify:</td>
    <td class="extra_field_input">
          <input style="display:none;" type="text" size="17" name="Other_County" value="" />
    </td>
</tr>
</table>
相关问题