我正在处理一个包含许多下拉框的表单,并且我已经从数据库中检索了下拉列表的值。一切都很完美,但现在我想添加一个提交按钮。在提交表单时,我想检索选定的下拉值及其 id。我不知道该怎么做。请帮助我。
提前致谢。
这是我的代码-
<!DOCTYPE html>
<html>
<?php
$db = JFactory::getDBO();
?>
<head>
<script>
var showClasses = {
};
function fnchecked(blnchecked,className)
{
if(blnchecked)
{
showClasses[className] = true;
}
else
{
showClasses[className] = false;
}
var ps = document.getElementById("div-block").children;
var psNumber = ps.length;
for (var i = 0; i < psNumber; i ++) {
var have = hasClasses(ps[i], showClasses);
if (have) {
ps[i].style.display = "";
} else {
ps[i].style.display = "none";
}
}
}
function hasClasses(element) {
var result = false;
for (var cls in showClasses) {
if (showClasses[cls]) {
if ((' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1) {
result = true;
}
}
}
return result
}
</script>
</head>
<body>
<form name="shohide1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div>
<label>Technologies: </label></br>
<input type="checkbox" name="technologies1" onChange="fnchecked(this.checked,'question1');" /> Kingspan Solar</br>
<input type="checkbox" name="technologies2" onChange="fnchecked(this.checked,'question2');" /> Solar PVT</br>
<input type="checkbox" name="technologies3" onChange="fnchecked(this.checked,'question3');" /> Insulation</br>
<input type="checkbox" name="technologies4" onChange="fnchecked(this.checked,'question4');" /> Gas boiler</br>
<input type="checkbox" name="technologies5" onChange="fnchecked(this.checked,'question5');" /> Oil boiler</br>
<input type="checkbox" name="technologies6" onChange="fnchecked(this.checked,'question6');" /> Heat recovery ventilation</br>
<input type="submit" name="formSubmit" value="Get The Info">
<div id="div-block" >
<p class=" question1 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=1';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class="question1 question2 question3 question4 question5 question6 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=2';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class="question1 question2 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=3';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class="question1 question2 question3 question4 question5 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=4';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question2 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=5';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question3 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=6';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question3 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=7';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question4 question5 question6 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=8';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question4 question5 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=9';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question4 question5 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=10';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question6 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=11';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
</div>
</div>
</body>
</html>