我已经创建了4个产品类别的列表。它工作正常并将所有值传递到下一页。
代码是:
echo "<tr><td>Product Category* </td>";
echo "<td>";
echo "<select size=\"1\" name=\"pc\" id=\"pc\">";
echo "<option value=\"0\">Product Category</options>";
echo "<option value=\"Hair\">Hair</options>";
echo "<option value=\"Skin\">Skin</options>";
echo "<option value=\"Nail\">Nail</options>";
echo "<option value=\"Eyes\">Eyes</options>";
echo "</select></td>";
我希望此列表将另外4个值(产品类别ID)与当前值一起传输到下一页。
答案 0 :(得分:0)
如果您不理解Juhana
的评论,这就是他的意思。
echo "<td>";
echo "<select size=\"1\" name=\"pc\" id=\"pc\">";
echo "<option value=\"0\">Product Category</options>";
echo "<option value=\"77\">Hair</options>";
echo "<option value=\"88\">Skin</options>";
echo "<option value=\"99\">Nail</options>";
echo "<option value=\"66\">Eyes</options>";
echo "</select></td>";
但是,如果你想通过JS / jQuery解决方案这样做。
<强>的jQuery 强>
$(function() {
$('#pc').change(function() {
var cat_id = $('option:selected', this).data(category_id);
$('#cat_id').val(cat_id);
});
});
<强> PHP 强>
echo "<td>";
echo "<select size=\"1\" name=\"pc\" id=\"pc\">";
echo "<option value=\"0\">Product Category</options>";
echo "<option data-category_id=\"77\" value=\"Hair\">Hair</options>";
echo "<option data-category_id=\"88\" value=\"Skin\">Skin</options>";
echo "<option data-category_id=\"99\" value=\"Nail\">Nail</options>";
echo "<option data-category_id=\"66\" value=\"Eyes\">Eyes</options>";
echo "</select></td>";
echo "<input type=\"hidden\" id=\"cat_id\" name=\"category_id\" />";
答案 1 :(得分:0)
为什么你不把这些id用作值?
echo "<tr><td>Product Category* </td>";
echo "<td>";
echo "<select size=\"1\" name=\"pc\" id=\"pc\">";
echo "<option value=\"0\">Product Category</options>";
echo "<option value=\"77\">Hair</options>";
echo "<option value=\"88\">Skin</options>";
echo "<option value=\"99\">Nail</options>";
echo "<option value=\"66\">Eyes</options>";
echo "</select></td>";
答案 2 :(得分:0)
echo "<tr><td>Product Category* </td>";
echo "<td>";
echo "<select size=\"1\" name=\"pc\" id=\"pc\">";
echo "<option value=\"0\">Product Category</options>";
echo "<option value=\"77-Hair\">Hair</options>";
echo "<option value=\"88-Skin\">Skin</options>";
echo "<option value=\"99-Nail\">Nail</options>";
echo "<option value=\"66-Eyes\">Eyes</options>";
echo "</select></td>";
并在服务器端分割“ - ”值