ヘルプが必要です。Select があり、隠しフィールドに各オプションのデータ (値ではない) を入力する必要があります。以下のコードを確認してください。
<script type="text/javascript">
$(document).ready(function($){
$('#retailer_id').change(function() {
var $selected = $('#retailer_id option:selected');
$('#slug_title').val($(this).val());
});
});
</script>
<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_title=\"".$row_retailers['slug_title']."\" value=\"".$row_retailers['retailer_id']."\"".$selected.">".$row_retailers['title']." </option>";
}
?>
</select>
現在、retailer_id が入力されていますが、( data-slug_title=\"".$row_retailers['slug_title']."\"
)で返される値を取得する必要があります
編集済み
HTML 出力:
<select class="textbox2" id="retailer_id" name="retailer_id">
<option value="">--- Please select store ---</option>
<option data-slug="casas-bahia-teste" value="4">Casas Bahia</option>
<option data-slug="direct-cosmetics" value="6">Direct Cosmetics</option>
<option data-slug="extra" value="3">Extra</option>
<option data-slug="flowers-direct" value="5">Flowers Direct</option>
<option data-slug="gem-motoring-assist" value="1">GEM Motoring Assist</option>
<option data-slug="pc-world-business" value="7">PC World Business</option>
<option data-slug="ponto-frio" value="10">Ponto Frio</option>
<option data-slug="red-house" value="2">Red House</option>
</select>
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#retailer_id').change( function() {
var $selected = $('#retailer_id option:selected');
$('input[name=slug]').val($selected.data('slug'));
});
});
</script>