我有一个下拉列表,其中包含来自数据库的客户名称。我希望这些值与我的'href'属性相关联。我该怎么做?
<select class="feedback-input" id="customer_selecter" name="customerName">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<a href="<?php echo base_url() . "index.php/edit/show_customer_id/" . $row->customerID; ?>">
<?php echo '<option value="'.$row->customerID.'">'.$row->customerName.'</option>'; ?></a>
<?php endforeach; ?>
</select>
答案 0 :(得分:0)
试试这个:
<select class="feedback-input" id="customer_selecter" name="customerName">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<a href="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>">
<option value="<?php echo $row->customerID; ?>"><?php echo $row->customerName; ?></option>
</a>
<?php endforeach; ?>
</select>
但这不是一个有效的HTML,因为你在<a>
代码中使用了<select>
代码,请尝试使用javascript代替这样做:
<select class="feedback-input" id="customer_selecter" name="customerName" onchange="location = this.value;">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<option value="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>"><?php echo $row->customerName; ?></option>
<?php endforeach; ?>
</select>