在这段代码中我没有找到解决方法如何让table1与数据。当table2在刷新table1的数据消失后显示!!我该如何解决这个问题?
<?php
$menucompare="";
if (isset($_POST["menucompare"]))
{
$menucompare= $_POST['menucompare'];
$table1 = '
<table id= "Table1" width="100%" border="1" cellspacing="0" cellpadding="0">
<!--SW - You need a tr tag around these headers-->
<th >Weeks</th>
<th ><p></p></th>
<th > More Details</th>
<tr id="tr">
<tr id= "tr " >
<td >gggg</td>
<td >kkkkk</td>
<td >
<form name ="dets" method="POST" action="">
<input class = "showt" name ="wnumber" id ="wnumber" type="submit" value= "More Details" />
<input type="hidden" name="data" value="wnumber" />
<noscript>
<input type="submit" value="Submit"/>
</noscript>
</form>
</td>
</tr>
</tr>
</table> ';
}
else if (isset($_POST["data"]))
{
// put whatever db process you need somwhere in this if statement
$table1 = '
<table id= "Table1" width="100%" border="1" cellspacing="0" cellpadding="0">
<!--SW - You need a tr tag around these headers-->
<th >Weeks</th>
<th ><p></p></th>
<th > More Details</th>
<tr id="tr">
<tr id= "tr " >
<td >gggg</td>
<td >kkkkk</td>
<td >
<form name ="dets" method="POST" action="">
<input class = "showt" name ="wnumber" id ="wnumber" type="submit" value= "More Details" />
<input type="hidden" name="row_id" value="value of row id" />
<input type="hidden" name="data" value="wnumber" />
<noscript>
<input type="submit" value="Submit"/>
</noscript>
</form>
</td>
</tr>
</tr>
</table> ';
$table2 = '
<div id="Table2">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<th id="wekkNum"> wnumber</th>
<th>Your place</th>
<th>Your arr</th>
</tr>
<tr >
<td>hhhh</td>
<td>kkkk</td>
<td>jjjj</td>
</tr>
</table>
</div>
';
}
?>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
/*Start Functions*/
function displayVals() {
var singleValues = $("select option:selected").text();
$("#hiddenselect").val(singleValues);
$("p").html("Procent of :    " + singleValues);
}
/*End functions*/
/*Start Ready*/
$(document).ready(function(){
$("select").change(function() {
displayVals();
});
displayVals();
$("select#menucompare").change(function() {
$("#aform").submit();
});
});
/*End Ready*/
</script>
<form id="aform" method="post">
<select id="menucompare" name ="menucompare" size="1" onchange="submitaform()">
<option selected='selected'>Select one</option>
<option value="value1" <?php if ($menucompare == "value1") { echo " selected='selected'"; } ?> >Text 1</option>
<option value="value2" <?php if ($menucompare == "value2") { echo " selected='selected'"; } ?> >Text 2</option>
<option value="value3" <?php if ($menucompare == "value3") { echo " selected='selected'"; } ?> >Text 3</option>
<option value="value4" <?php if ($menucompare == "value4") { echo " selected='selected'"; } ?> >Text 4</option>
</select>
<input type="hidden" name="hiddenselect" value="<?php echo $menucompare ; ?>" />
</form>
<?php
if (isset($table1))
{
print $table1;
}
if (isset($table2))
{
print $table2;
}
?>
这是我的整个代码。 希望有解决方法,我看了所有的帖子,但没有类似的问题。
答案 0 :(得分:3)
/*Start Ready*/
$(document).ready(function(){
$("select").change(function() {
displayVals();
});
displayVals();
此代码段中的第二个displayVals();
会在页面加载时立即触发,我希望这是您错误的原因,因为在页面加载时尚未选择任何内容。
您的table2不会显示在页面加载或页面刷新(这只是强制页面加载),因为您具有内联样式<div id="Table2" style="display:none;">
。您期望保留选择选项的类似问题...如果页面刷新,则会重置为其默认状态,因此没有选择选项。
答案 1 :(得分:1)
$ _ POST值仅在表单提交后立即在页面上提供。
通过多个页面保持用户输入的简单方法是将其作为隐藏的表单字段传递。
因此,您需要在“dets”表单中添加隐藏的表单字段:
<input type="hidden" name="menucompare" value="'. $menucompare.'" />
此外,你必须摆脱第37行的“其他”
else if (isset($_POST["data"]))
到
if (isset($_POST["data"]))