在ZEND的选择下拉列表中选择后的Onchange事件

时间:2015-02-16 11:27:34

标签: php zend-framework html-select selectionchanged

我有一个使用select标签的下拉列表视图,我想在下拉列表中选择一个值之后如何才能有事件或onchange事件。

这是我在index.phtml中的代码

    <?php if (count($users)): ?>
    <table class="table table-hover">
    <thead>
    <tr>
        <th>Name</th>
        <th>E-mail</th>
        <th>Level</th>
        <th></th>
      </tr>
    </thead>
    <?php foreach ($users as $user): ?>
   <tr>
        <td><a href="<?php echo $this->url('user/edit', array('id' => $user->id)); ?>"><?php echo $this->escapeHtml($user->first_name . ' ' . $user->last_name); ?></a></td>
        <td><?php echo $this->escapeHtml($user->email); ?></td>
        <td>
            <select name="level">

            <?php $level = $this->escapeHtml($user->level); ?>

            <?php if ($level == 1): ?>
                 <option value="1" selected="selected">Administrator</option>
                 <option value="2">Manager</option>
                 <option value="3">HR Staff</option>
             <?php elseif ($level == 2): ?>
                 <option value="1" >Administrator</option>
                 <option value="2" selected="selected">Manager</option>
                 <option value="3">HR Staff</option>
               <?php elseif ($level == 3): ?>
                 <option value="1" >Administrator</option>
                 <option value="2" >Manager</option>
                 <option value="3" selected="selected">HR Staff</option>
                <?php endif; ?>
            </select>
        </td>
        <td style="text-align: right;">
            <a href="<?php echo $this->url('user/delete', array('id' => $user->id)); ?>" class="btn btn-mini btn-danger" rel="tooltip" title="Delete this user"><i class="icon-remove icon-white"></i></a>
        </td>
    </tr>
    <?php endforeach; ?>
    </table>
<?php else: ?>
<h3>There are no registered users available.</h3>
<?php endif; ?>

先谢谢

1 个答案:

答案 0 :(得分:2)

创建javascript函数并将函数放在onchange事件的选择框中。

查看fiddle

上的工作示例
<script>
 function changeTest(obj){
    alert(obj.options[obj.selectedIndex].value);
  }
</script>

 <select name="level" onChange="changeTest(this)">
   <option value="1" selected="selected">Administrator</option>
             <option value="2">Manager</option>
             <option value="3">HR Staff</option>
 </select>
相关问题