Code to have client choose departments, and help topics
Well, it's taken me longer than I expected to get around to this, but here is the code I used to create different department help topics. This is just a little validation type thing. Which select menu they get depends on which radio button they press.
There is still an error, I'm trying to figure out. The new select box pops up outside the form. So, hopefully I'll be able to figure that one out soon. Or if someone else knows, feel free to add some input.
First, here is a the snip from my open.inc.php file, basically I just added the departments heading and modified the help topics heading.
<th>Telephone:</th>
<td><input type="text" name="phone" size="25" value="<?=$info?>"> <font class="error"> <?=$errors?></font></td>
</tr>
<tr height=2px><td align="left" colspan=2 > </td</tr>
<tr>
<th>Department:</th>
<td>
<?php
include("workOrder.js");
?>
<input type="radio" name="form_type" value="I.T."
onClick="switchDiv('I.T.');">I.T. Request
<input type="radio" name="form_type" value="P.R."
onClick="switchDiv('P.R.');">P.R. Request
<font class="error">* <?=$errors?></font>
</td>
</tr>
<tr>
<th>Help Topic:</th>
<td>
<div id="I.T." style="position;visibility;top;left;">
<select name="IT">
<option selected>Please choose</option>
<?
$services= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.' WHERE isactive=1 AND dept_id = 1 ORDER BY topic');
while (list($topicId,$topic) = db_fetch_row($services)){
$selected = ($info==$topicId)?'selected':''; ?>
<option value="<?=$topicId?>"<?=$selected?>><?=$topic?></option>
<? } ?>
</select>
<font class="error">* <?=$errors?></font>
</div>
<div id="P.R." style="position;visibility;top;left;">
<select name="PR">
<option selected>Please choose</option>
<?
$services= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.' WHERE isactive=1 AND dept_id = 2 ORDER BY topic');
while (list($topicId,$topic) = db_fetch_row($services)){
$selected = ($info==$topicId)?'selected':''; ?>
<option value="<?=$topicId?>"<?=$selected?>><?=$topic?></option>
<? } ?>
</select>
<font class="error">* <?=$errors?></font>
</div>
</td>
</tr>
<tr>
<th>Subject:</th>
<td>
<input type="text" name="subject" size="35" value="<?=$info?>">
<font class="error">* <?=$errors?></font>
</td>
Next here is the Javascript file that the php is including in the departments heading.
<script type="text/javascript">
function switchDiv(div_id)
{
var style_sheet = getStyleObject(div_id);
if (style_sheet)
{
hideAll();
changeObjectVisibility(div_id,"visible");
}
else
{
alert("There was an error. Please contact someone@somewhere.com");
}
}
// function hideAll()
// hides a bunch of divs
//
function hideAll()
{
changeObjectVisibility("I.T.","hidden");
changeObjectVisibility("P.R.","hidden");
}
function getStyleObject(objectId) {
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
}
else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
}
else if (document.layers && document.layers) {
return document.layers;
} else {
return false;
}
}
function changeObjectVisibility(objectId, newVisibility) {
var styleObject = getStyleObject(objectId);
if(styleObject) {
styleObject.visibility = newVisibility;
return true;
} else {
return false;
}
}
//
</script>