Input value disappeared.
Posted: Tue Apr 17, 2007 5:51 pm
I've a script that has an input called "subject" and two dynamic drop down boxes one drop down is called "department" and the other drop down is called "lst_ategories", I input a value for the subject and then choose a department, some how the value of the Subject got wiped out. Could someone give me some ideas why it's doing that. Please see my code below. Thanks...
Code: Select all
<?php
?>
<SCRIPT LANGUAGE=javascript>
function selDept(obj)
{
document.getElementById("hidDept").value=obj.options[obj.options.selectedIndex].value
if(document.getElementById("hidDept").value!="")
{
document.getElementById ("frmDept").submit()
}
}
function setFocus2(chosen)
{
document.frmTicket.message.focus();
}
var formInUse = false;
function setFocus()
{
if(!formInUse) {
document.frmTicket.subject.focus();
}
}
</SCRIPT>
<body onload="setFocus()">
<form name="frmDept" id="frmDept" method="post" action="">
<input type="hidden" name="hidDept" id="hidDept" value="<?php echo $tmpDept; ?>">
</form>
<form name="frmTicket" method="post" enctype="multipart/form-data">
<tr align="left" valign="bottom">
<td width="130"><b><br><font color="#<?php echo $fontsubject ?>">Subject</font></b></td>
<td><input name="subject" type="text" size="100" id="subject" value="<?php if(isset($_SESSION["subject"])){ echo $_SESSION["subject"]; } ?>"> *</td>
</tr>
<tr align="left" valign="center">
<td><br><font color="#<? echo $fontdep ?>">Department</font></td>
<td><br>
<select name="department" id="department" onchange="javascript:selDept(this)">
<?php
$str = "select * from tbl_departments ";
$res = mssql_query($str) or die(mssql_error());
?>
<?
while($data = mssql_fetch_array($res))
{
$tmp_dept = $data["department"];
?>
<option value = "<?=$data['id']?>" <?=(isset($_POST['department']) && $_POST['department'] == $data['id'] ? "selected=\"selected\"" : "");?>><?=$tmp_dept?>
</option>
<?php
}
?>
</select></td>
</tr>
<tr align="left" valign="center">
<td width="130"><font color="#<? echo $fontcategories ?>">Problem/Request Type</font></td>
<td width="600">
<?php
if ($tmpDept <= 0) {$tmpDept = 1;}
$str = "select * from tbl_categories WHERE dept_id =".$tmpDept." order by categories";
$res = mssql_query($str) or die(mssql_error());
?>
<select name = "lst_categories" id="lst_categories" onchange="javascript:setFocus2(this)">
<option value = "">[Select One]</option>
<?
$clr_flag = 0;
while($data = mssql_fetch_array($res))
{
if ($clr_flag == 1) {$clr = "white"; $clr_flag=0;}
else {$clr = "mar"; $clr_flag=1;}
$i_id = $data["id"];
$s_categ = $data["categories"];
?>
<option value = "<?=$s_categ?>" class = "<?echo $clr;?>">
<?=$s_categ?>
</option>
<?
}
?>
</select> *
</td>
</tr>
<br>
</form>
</body>