这就是我成功完成的工作。
这是我做不到的事情
这是我的index.html文件
<tr>
<td colspan="4" align="left" class="form-group form-inline"><b>Section
B</b></td>
</tr>
<script type="text/javascript">
function show() {
var dropdown = document.getElementById("employment");
var current_value =
dropdown.options[dropdown.selectedIndex].value;
if(current_value =="--Choose one--"){
didfv3.style.display = 'none';
didfv2.style.display = 'none';
}
if(current_value == "Unemployed"){
didfv3.style.display = 'none';
didfv2.style.display = '';
}
if(current_value == "Working"){
didfv3.style.display = '';
didfv2.style.display = 'none';
}
}
</script>
<td>employment</td>
<td colspan="4">
<select name="employment" id="employment" onChange="show();">
<option value="--Choose one--">--Choose one--</option>
<option value="Unemployed">Unemployed</option>
<option value="Working">Working</option>
</select>
<table id="didfv2" width="90%" border="0" align="center"
style="display:none">
<tr>
<td width="50%">Balance</td>
<td width="1%" align="center">:</td>
<td width="73%" ><input type="text" name="balance" readonly maxlength="10"
value="<?php echo $balance?>" size="5" > months</td>
</tr>
</table>
<table id="didfv3" width="90%" border="0" align="left"
style="display:none">
<tr>
<td class="form-group form-inline">Basic Salary</td>
<td width="0.5%" align="knk" class="form-group form-inline">:</td>
<td width="73%" class="form-group form-inline">
<input name="basic" type="text" id="basic" maxlength="20"/></td>
</tr>
<tr>
<td>Gross Salary</td>
<td width="0.5%" align="center" class="form-group form-inline">:</td>
<td width="73%" class="form-group form-inline">
<input name="gross" type="text" id="gross" maxlength="20"/></td>
</tr>
<tr>
<td class="form-group form-inline">Nett Salary</td>
<td width="0.5%" align="center" class="form-group form-inline">:</td>
<td width="73%" class="form-group form-inline">
<input name="nett" type="text" id="nett" maxlength="20"/></td>
</tr>
<tr>
</table>
这是我的insert.php
<?
$employment = $_POST['xxx'];
if (isset($_POST['xxx'])) {
$employment =$_POST['xxx'];
}
if($employment =='Working'){
$basic = $_POST['basicsalary00'];
$gross = $_POST['grosssalary00'];
$nett = $_POST['nettsalary00'];
}
elseif($xxx =='Unemployed'){
$balance = $_POST['balance'];
}
$sqlinsert = "INSERT INTO application
(
xxx,basicsalary00,grosssalary00,nettsalary00)
VALUES(0,'$xxx','$basic','$gross','$nett')";
?>
// here is to print back the output
<form name="formName" action="form1" method="post" class="form-group form-
inline">
<tr>
<td rowspan="2">Employment</td>
<td colspan="3">
<option value="<?php echo $employment;?>"><?php echo $employment;?>
</option>
<table id="didfv2" width="90%" border="0" align="center"
style="display:none">
<tr>
<td colspan="3">
<input type="hidden" id="balance" value="<?php echo $balance;?>" />
</td>
</tr>
</table>
<table id="didfv3" width="90%" border="0" align="center"
style="display:none">
<tr></tr>
<tr>
<td>Basic Salary</td>
<td>
<input name="basic" type="hidden" id="basic" value="<?php echo $basic;?>" />RM <?php echo $basic;?></td>
</tr>
<tr>
<td>Gross Salary</td>
<td>
<input name="gross" id="gross" type="hidden" value="<?php echo $gross;?>"
/>RM <?php echo $gross;?></td>
</tr>
<tr>
<td>Nett Salary</td>
<td>
<input name="nett" type="hidden" id="nett" value="<?php echo $nett;?>"
/>RM <?php echo $nett;?></td>
</tr>
</table>
</td>
</tr>
</form>
所以会有4页,
1)供用户输入(index.html)
2)预览输入(我没有在此处包含文件-成功)
3)将输入插入db(insert.php)
4)打印出结果(代码在insert.php ...从db-提取的底部,但我失败了。适用于其他字段,但不适用于下拉部分)
我真的需要你的帮助..我已经在这里呆了一个星期....谢谢
答案 0 :(得分:0)
适当的下拉菜单应包含<select>
,其中应包含<option>
元素!
在您的insert.php
中,我看到您仅使用了以下行:
<option value="<?php echo $employment;?>"><?php echo $employment;?></option>
如何尝试这样:
<select readonly>
<option value="--Choose one--">--Choose one--</option>
<option <?php echo ($employment == 'Unemployed') ? 'selected' : ''; ?> value="Unemployed">Unemployed</option>
<option <?php echo ($employment == 'Working') ? 'selected' : ''; ?> value="Working">Working</option>
</select>
在这里,我们正在检查那些<option>
元素是否与用户提交的元素相同。如果是这样,将其设置为selected
希望有帮助。
编辑
如果要存储$employment
的值以便以后显示,则必须将其存储在数据库中。