我有一个从数据库retailer_id 中获取选项的选择输入,我需要它,当管理员在此选择输入上选择一个零售商时,我将使用retailer_slug 获得一个新的,然后,当管理员创建或更新时,将发送到数据库中隐藏输入的retailer_id 和retailer_slug。我的代码是:
已编辑
<select class="textbox2" id="retailer_id" name="retailer_id">
<option value="">--- Please select store ---</option>
<?php
$sql_retailers = smart_mysql_query("SELECT * FROM cashbackengine_retailers WHERE status='active' ORDER BY title ASC");
while ($row_retailers = mysql_fetch_array($sql_retailers))
{
if ($retailer_id == $row_retailers['retailer_id']) $selected = " selected=\"selected\""; else $selected = "";
echo "<option data-slug=\"".$row_retailers['slug_title']."\" value=\"".$row_retailers['retailer_id']."\"".$selected.">".$row_retailers['title']."</option>";
}
?>
</select>
<input type="text" name="slug" id="slug" value=""/>
<script type="text/javascript">
$(document).ready(function() {
$('#retailer_id').on('change', function() {
var $selected = $('#retailer_id option:selected');
$('input[name=slug]').val($selected.data('slug'));
});
});
</script>