社区中利用多个变量,我目前有一个select下拉菜单,其值和标题正通过mysql查询填充。目前,它传递的是(source_id)。但是,我希望它也传递第二个变量(source_flag)。我需要这两个原因如下。如果source_flag设置为'YES',那么我的JS会使div可见。我需要(source_id)将值插回到我的数据库中。下面是我目前的下拉和JS功能。添加一点HTML。在选择选项
HTML
<fieldset style="display: inline;" id="source">
<legend class="legend1"><h2> Ticket Source </h2></legend>
<div style="padding-top: 5px;" id="source">
<div class="input-field">
<?php include $ins_tic.'selectSource'.$ext; ?>
</div>
<div id="received" style="display: none;">
<input type="text" id="dateTimeField" name="received_on" style="width: 160px;" placeholder="Time Received"/>
<script>AnyTime.picker('dateTimeField');</script>
</div>
</div>
</fieldset>
的$ ins_tic.'selectSource”。$ EXT文件
<?php
//This populates the drop down
echo '
<select id="ticket_source" name="ticket_source" tabindex="16" onchange="showEmail(this.value)">
<option value="">Select Source</option>';
//I want to add source_flag to the query, and add that value to the select option
$get_sources = mysql_query("SELECT source_id, source_name FROM ticket_source ORDER BY source_name ASC");
while (($source_list = mysql_fetch_assoc($get_sources)))
{
echo '
<option value="'.$source_list['source_id'].'">'.$source_list['source_name'].'</option>';
};
echo '
<option value="0">Other</option>
</select>';
?>
最后,我目前的JavaScript。请注意,JavaScript目前正在关闭source_id值。我不喜欢这样做,因为未来可能会或可能会添加其他来源。
function showEmail(id)
{
var div = document.getElementById("received");
if(id == 2 || id == 3 || id == 5)
{
div.style.display = 'block';
}
else
{
div.style.display = 'none';
}
}
当我做警报(标志)
;它什么也没有显示。是否还有其他需要添加的东西来获取“”或“YES”的值? –
@CBC_NS你可以展示你的整个代码吗?我会为你提供一些jsfiddle,它应该可以工作。看到源代码中的标志是吗? –
我真的想出了一个解决方案,我用var flag = element.options [element.selectedIndex] .getAttribute('data-flag');来得到标志的值 –