【发布时间】:2015-06-03 09:51:26
【问题描述】:
我在一个表单中有两个文本框和两个下拉菜单。在文本框中填充值并从下拉列表中选择值后,页面会重新加载,并根据下拉列表中选择的值填充其他下拉列表。但是文本框中的值不存在。如何保留这些文本框的值。
<html>
<head>
</head>
<body>
<form action="selectmultiplepost.php" method="post" name="myform">
First Name<input type="text" name="firstname" value=""><br>
Last Name<input type="text" name="lastname" value=""><br>
Industry Name <select name="industryid" id="industrySelect" onchange="document.location.href = 'selectmultiple.php?industryid=' + this.value">
<option>SELECT</option>
<?php
include('config.php');
$query = "select IndustryId, IndustryName from industrytable";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
while($fetch = mysql_fetch_array($result))
{
?>
<option value="<?php echo $fetch['IndustryId'];?>"><?php echo $fetch['IndustryName'];?></option>
<?php
}
}
?>
</select><br>
Skills <select name="skillname">
<option>SELECT</option>
<?php
include('config.php');
if(isset($_GET['industryid']))
{
$industryID = $_GET['industryid'];
}
else
{
$industryID = "";
}
$skillQuery = "select SkillId, SkillName from skilltable where Industryid='".$industryID."'";
$resultSkill = mysql_query($skillQuery);
if(mysql_num_rows($resultSkill) > 0)
{
while($fetch = mysql_fetch_array($resultSkill))
{
?>
<option value="<?php echo $fetch['SkillId'];?>"><?php echo $fetch['SkillName'];?></option>
<?php
}
}
?>
</select><br>
<input type="submit" name="submitform" value="submit"/>
</form>
<script>
document.getElementById('industrySelect').value = "<?php echo $_GET['industryid'];?>";
</script>
</body>
</html>
【问题讨论】:
标签: php forms drop-down-menu onchange retain