I am having an issue with hiding/showing elements. If you preview my code, you’ll see that, based upon a selection in a drop-down menu, I need certain fields to display. However, some fields are common among the drop-down menu selections…and if you preview it, you’ll see that the elements are not displayed very cleanly- lots of annoying spaces in between fields, etc.
Is there a better way to write this to avoid this problem? I’ve read a bit about DOM and parent containers, but am a JS newbie. Was wondering if something like that would accomplish this to make the page results more cleanly? Or, perhaps something else?
Thanks!
[code=html]
<head>
<title>Project Input</title>
</head>
<body>
<form name=”frmInput” id=”frmInput” method=”post”>
<!– Entry Type –>
<div class=”WebApps”>
<h3><label for=”cboEntryType”>Entry Type</label></h3>
<p>
<select name=”cboEntryType” id=”cboEntryType”>
<option></option>
<option value=”1″>Project</option>
<option value=”2″>Test Initiative</option>
<option value=”3″>Business Initiative</option>
<option value=”4″>Business Enhancement</option>
<option value=”4″>Problem Ticket</option>
</select></p>
</div>
<!– Name –>
<div id=”txtName” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtName”>Name:</label></h4>
</td>
<td>
<p><input type=”text” name=”txtName” id=”txtName” size=”100″ maxlength=”100″ /></p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Description –>
<div id=”txtDescription” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtDescription”>Description: </label></h4>
</td>
<td>
<p><textarea name=”textarea” id=”txtProjectDescription” cols=”100″ rows=”5″></textarea></p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Merger –>
<div id=”cbMerger” class=”WebApps” style=”display:none”>
<table width=”261″ border=”1″>
<tr>
<td width=”217″>
<h4><label for=”cbMerger”>This is a merger initiative.</label></h4>
</td>
<td width=”57″>
<p><input type=”checkbox” name=”cbMerger” id=”cbMerger” /></p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Number –>
<div id=”txtNumber” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtNumber”>Number:</label></h4>
</td>
<td>
<p><input type=”txtNumber” id=”txtNumber” size=”20″ /></p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Target Completion Date –>
<div id=”txtTargetCompletionDate” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtTargetCompletionDate”>Target Completion Date:</label></h4>
</td>
<td>
<p><input type=”txtTargetCompletionDate” id=”txtTargetCompletionDate” size=”10″ /></p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Owner –>
<div id=”cboOwner” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”cboOwner”>Owner: </label></h4>
</td>
<td>
<p>
<select name=”cboOwner” id=”cboOwner”>
<option></option>
</select>
</p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Application –>
<div id=”cboApplication” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”cboApplication”>Application: </label></h4>
</td>
<td>
<p>
<select name=”cboApplication” id=”cboApplication”>
<option></option>
</select>
</p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– TIG Application –>
<div id=”cboTIGApplication” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”cboPriority”>TIG Application: </label></h4>
</td>
<td>
<p>
<select name=”cboTIGApplication” id=”cboTIGApplication”>
<option></option>
</select>
</p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Priority –>
<div id=”cboPriority” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”cboPriority”>Priority: </label></h4>
</td>
<td>
<p>
<select name=”cboPriority” id=”cboPriority”>
<option></option>
</select>
</p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Severity –>
<div id=”cboSeverity” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”cboSeverity”>Severity: </label></h4>
</td>
<td>
<p>
<select name=”cboSeverity” id=”cboSeverity”>
<option></option>
</select>
</p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Contact –>
<div id=”cboContact” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”cboContact”>Contact: </label></h4>
</td>
<td>
<p>
<select name=”cboContact” id=”cboContact”>
<option></option>
</select>
</p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– High Level Sizing –>
<div id=”txtSizing” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtSizing”>High Level Sizing: </label></h4>
</td>
<td>
<p><input type=”txtSizing” id=”txtSizing” size=”20″ /></p>
</td>
</tr>
</table>
</div>
<!– Project Manager –>
<div id=”txtPMFirstName” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtPMFirstName”>First Name: </label></h4>
</td>
<td>
<p><input type=”txtPMFirstName” id=”txtPMFirstName” size=”20″ /></p>
</td>
</tr>
</table>
</div>
<p class=”BoxCsubheadersnotes”> </p>
<!– Project Manager –>
<div id=”txtPMLastName” class=”WebApps” style=”display:none”>
<table border=”1″>
<tr>
<td>
<h4><label for=”txtPMLastName”>Last Name: </label></h4>
</td>
<td>
<p><input type=”txtPMLastName” id=”txtPMLastName” size=”20″ /></p>
</td>
</tr>
</table>
</div>
</form>
</body>
<script language=”javascript”>
window.onload = function()
{
(document.getElementById(“cboEntryType”).onchange = displayEntryTypes);
};
function displayEntryTypes()
{
var cboEntryType = (document.getElementById(“cboEntryType”).value);
var txtName = document.getElementById(“txtName”);
var txtNumber = document.getElementById(“txtNumber”);
var txtTargetCompletionDate = document.getElementById(“txtTargetCompletionDate”);
var cboOwner = document.getElementById(“cboOwner”);
var cboContact = document.getElementById(“cboContact”);
var txtDescription = document.getElementById(“txtDescription”);
var txtPMFirstName = document.getElementById(“txtPMFirstName”);
var txtPMLastName = document.getElementById(“txtPMLastName”);
var txtSizing = document.getElementById(“txtSizing”);
var cbMerger = document.getElementById(“cbMerger”);
var cboApplication = document.getElementById(“cboApplication”);
var cboPriority = document.getElementById(“cboPriority”);
var cboTIGApplication = document.getElementById(“cboTIGApplication”);
var cboSeverity = document.getElementById(“cboSeverity”);
txtName.style.display = “none”;
txtNumber.style.display = “none”;
txtTargetCompletionDate.style.display = “none”;
cboOwner.style.display = “none”;
cboContact.style.display = “none”;
txtDescription.style.display = “none”;
txtPMFirstName.style.display = “none”;
txtPMLastName.style.display = “none”;
txtSizing.style.display = “none”;
cbMerger.style.display = “none”;
cboApplication.style.display = “none”;
cboPriority.style.display = “none”;
cboTIGApplication.style.display = “none”;
cboSeverity.style.display = “none”;
if (cboEntryType == “1”) //1 is Project
{
txtName.style.display = “”;
txtNumber.style.display = “”;
txtTargetCompletionDate.style.display = “”;
cboOwner.style.display = “”;
cboContact.style.display = “”;
txtPMFirstName.style.display = “”;
txtPMLastName.style.display = “”;
txtDescription.style.display = “”;
}
if (cboEntryType == “2”) //2 is Test Initiative
{
txtName.style.display = “”;
txtNumber.style.display = “”;
txtTargetCompletionDate.style.display = “”;
cboOwner.style.display = “”;
cboContact.style.display = “”;
txtSizing.style.display = “”;
txtDescription.style.display = “”;
}
if (cboEntryType == “3”) //3 is Business Initiative
{
txtName.style.display = “”;
txtNumber.style.display = “”;
txtTargetCompletionDate.style.display = “”;
cboOwner.style.display = “”;
cboContact.style.display = “”;
txtDescription.style.display = “”;
cbMerger.style.display = “”;
}
if (cboEntryType == “4”) //4 is Business Enhancement
{
txtName.style.display = “”;
txtNumber.style.display = “”;
txtTargetCompletionDate.style.display = “”;
cboOwner.style.display = “”;
cboContact.style.display = “”;
txtDescription.style.display = “”;
cboApplication.style.display = “”;
cboPriority.style.display = “”;
}
if (cboEntryType == “5”) //4 is Problem Ticket
{
txtName.style.display = “”;
txtNumber.style.display = “”;
txtTargetCompletionDate.style.display = “”;
cboOwner.style.display = “”;
cboContact.style.display = “”;
txtDescription.style.display = “”;
cboTIGApplication.style.display = “”;
cboSeverity.style.display = “”;
}
}
</script>