我有顯示名稱的表,但它的價值是它的用戶id,電子郵件和水平如何通過在onchange事件兩個或多個參數
<?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" id= "level" onchange="changeLevel(this);">
<?php $level = $this->escapeHtml($user->level); ?>
<?php if ($level == 1): ?>
<option value="1" selected ="selected">Administrator</option>
<option value="2" <?php IsSelected($level,2); ?>> Manager</option>
<option value="3" <?php IsSelected($level,3); ?>>HR Staff</option>
<?php elseif ($level == 2): ?>
<option value="1" <?php IsSelected($level,1); ?>>Administrator</option>
<option value="2" selected ="selected">Manager</option>
<option value="3" <?php IsSelected($level,3); ?>>HR Staff</option>
<?php elseif ($level == 3): ?>
<option value="1" <?php IsSelected($level,1); ?>>Administrator</option>
<option value="2" <?php IsSelected($level,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; ?>
,現在來看,我的選擇下拉onchange事件僅傳遞值在下拉到AJAX函數調用一個Zend controlelr
這裏所選擇的值的是AJAX功能
<script>
changeLevel = function(level){
var level_value = level.value;
var user_id =
alert(level.value);
$.ajax({
type: "POST",
url: 'http://localhost/ijm/public/user/level',
data: { function_params: level_value },
Success: function(result){
alert('Success');
}
});
}
</script>
和這裏是用戶控制器功能
public function levelAction()
{
$storage = $this->getAuthService()->getStorage();
$user = $storage->read();
$request = $this->getRequest();
$level = $request->getPost('function_params');
echo $level;
// Check if form values are valid
$this->getUserTable()->editLevel($user->id, $level);
$this->redirect()->toRoute('user');
echo "success";
}
我要的是每次我觸發onchange事件我也希望用戶id要在onchange事件傳遞的功能,這樣我可以在我的Zend控制器上發送。我怎樣才能做到這一點?提前致謝。
謝謝!這個竅門! – Dave 2015-02-23 10:31:31