我知道我在这里缺少一些基本的东西,但对于我的生活,我无法弄清楚这一点。
我需要隐藏的输入字段来反映用户在下拉菜单中选择的课程。
=============================================== ======================
<p><b>1. Select Course:</b></p>
<?php
$db = JFactory :: getDBO();
$query = "select name from #__guru_category order by name ASC";
$db->setQuery($query);
$result = $db->loadObjectList();
$options = array();
$options[] = JHTML::_('select.option','Select Course');
foreach($result as $row)
{
$options[] = JHTML::_('select.option', $row->name);
}
$dropdown = JHTML::_('select.genericlist', $options, 'class="inputbox"', 'subject', 'value', 'text');
echo $dropdown;
?>
<p><b>2. Select assignment file to upload:</b></p>
<p><input type="file" name="fileToUpload" id="fileToUpload"></p>
**<input type="hidden" name="subject" id="subject" value="">**
<p><input type="submit" value="Upload Assignment File" name="submit"></p>
</form>
=============================================== =====
答案 0 :(得分:0)
$dropdown = JHTML::_('select.genericlist', $options, 'class="inputbox"', 'subject', 'value', 'text');
您错过了参数值orderlist
genericlist($arr, $name, $attribs=null, $key= 'value', $text= 'text', $selected=NULL, $idtag=false, $translate=false)
链接: https://docs.joomla.org/API15:JHTMLSelect/genericlist
此解决方案
<?php
$db = JFactory :: getDBO();
$query = "select name from #__guru_category order by name ASC";
$db->setQuery($query);
$result = $db->loadObjectList();
$options = array();
$attr = 'onchange="UpdateUsername(this.options[this.selectedIndex].value);"';
$attr .= ' class="inputbox"';
$options[] = JHTML::_('select.option','Select Course');
foreach($result as $row){
$options[] = JHTML::_('select.option', $row->name);
}
$dropdown = JHTML::_('select.genericlist', $options,'subject',$attr, 'value', 'text');
echo $dropdown;
?>
<p><b>2. Select assignment file to upload:</b></p>
<p><input type="file" name="fileToUpload" id="fileToUpload"></p>
<input type="hidden" name="subject" id="subject" value="">
<p><input type="submit" value="Upload Assignment File" name="submit"></p>
<script type="text/javascript">
function UpdateUsername(selected){
document.getElementById(subject).value= selected;
}
</script>