I don't mean to sound like a drill sergeant; it's sometimes hard for me to gauge how much force I'm putting into my statements (and how much others intended in theirs). Plus going through a lot of poorly formatted sources gets old fast - but the experience and ideas I get are easily worth it.
Just to check... Do you use Design View (or Mode, or whatever it is) in Dreamweaver? If so, please stop; the worst coder in the world is surely a WYSIWYG.
Also, I advise you to post this page in the HTML forum and ask what could be done better. Using a lot more CSS instead of all the styling HTML attributes is the first thing I would suggest. Not using tables so much might be the second; if not, using table headers would be.
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Weekly Direct Report for </title>
<link href="index_files/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//function to unhide fields
function hide(){
if(document["WDR"]["Travel"].checked)
{
document.getElementById("TravelExpTD").style.visibility="visible"
document.getElementById("TravelExpODCTD").style.visibility="visible"
}
else
{
document.getElementById("TravelExpTD").style.visibility="hidden"
document.getElementById("TravelExpODCTD").style.visibility="hidden"
}
}
</script>
</head>
<body>
<!-- Connect to the Database -->
<form name="WDR" action="Add_WDR.php" method="post">
<div id="container">
<table border="0" width="100%">
<tbody>
<tr>
<td colspan="2"><!-- <img src="" alt="IMG" /> --></td>
<td colspan="4" align="left">
<span class="heading">Weekly Direct Report</span><br />
</td>
</tr>
<tr>
<td colspan="6">
<hr />
</td>
</tr>
</tbody>
</table>
<div class="mainindexTable">
<table border="0" width="100%">
<tbody>
<tr>
<th align="left">UserName:</th>
<th align="left">Date:</th>
<th align="left">Anticipated Travel:</th>
<th align="left">Anticipated Leave:</th>
</tr>
<tr>
<td width="21%">
<input name="UserName" id="UserName" size="16" maxlength="16" disabled="disabled" value="" type="text" />
</td>
<td width="13%">
<input name="ReportDate" id="ReportDate" size="8" maxlength="8" type="text" />
</td>
<td width="17%">
<select name="AnticipatedTravel">
<option value="No" selected="selected">No</option>
<option value="Yes">Yes</option>
</select>
</td>
<td width="49%">
<select name="AnticipatedLeave">
<option value="No" selected="selected">No</option>
<option value="Yes">Yes</option>
</select>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<!--<tr>
<td colspan="4">
<input type="button" name="AddDO" id="AddDO" value="Add Another DO" />
</td>
</tr> -->
</tbody>
</table>
</div>
<div id="DOandHours" class="mainindexTableBG">
<table style="display: block;" id="Table" border="0" width="100%">
<tbody>
<tr>
<td width="16%">
<input name="AddDO" id="AddDO" value="Add Another DO" type="button" />
</td>
</tr>
<tr>
<th align="left">Select DO:</th>
<th align="left">Hours:</th>
<th align="left">Travel on this DO:</th>
<th align="left">Travel Expense:</th>
<th align="left">OCD Travel Expense:</th>
</tr>
<tr>
<td>
<select name="DO1">
<option value="#" selected="selected">Select DO</option>
<option name="DONum[][]" value="9987.99.01">9987.99.01</option>
<option name="DONum[][]" value="9032.90">9032.90</option>
<option name="DONum[][]" value="5993.02">5993.02</option>
<option name="DONum[][]" value="1234.56">1234.56</option>
</select>
</td>
<td width="9%">
<input name="RegularHours[][]" id="RegularHours" size="8" maxlength="8" type="text" />
</td>
<td width="12%">
<input name="Travel" value="Yes" onclick="hide()" type="checkbox" />Yes
</td>
<td id="TravelExpTD" style="visibility: hidden;" width="15%">
$<input name="TravelExp[][]" id="TravelExp" size="15" maxlength="15" type="text" />
</td>
<td id="TravelExpODCTD" style="visibility: hidden;" width="18%">
$<input name="TravelExpODC[][]" id="TravelExpODC" size="15" maxlength="15" type="text" />
</td>
</tr>
</tbody>
</table>
</div>
<div id="TaskAndHighlights" class="mainindexTableTask">
<table border="0" width="100%">
<tbody>
<tr>
<td><input value="Add Another Task" id="AddTask" type="button" /></td>
</tr>
<tr>
<th align="left">Task:</th>
</tr>
<tr>
<td>
<select name="WorkedTask[0][]" id="WorkedTask">
<option value="#" selected="selected">Task Name</option>
<option value="Hello World">Hello World</option>
<option value="Somthing Else">Something Else</option>
<option value="Training">Training</option>
<option value="Whatever">Whatever</option>
</select>
</td>
</tr>
<tr>
<th align="left">Highlights:</th>
<th align="left">Select Common Task:</th>
</tr>
<tr>
<td width="34%"><input name="Highlights[0][]" id="Highlights" size="50" maxlength="100" type="text" /></td>
<td width="34%">
<select name="CommonTask[0][]" id="CommonTask">
<option value="#" selected="selected">Common Tasks</option>
<option value="Security Meeting."> Security Meeting. </option>
<option value="SWWG Meeting"> SWWG Meeting </option>
</select>
</td>
<td width="32%"><input value="Add another Highlight" id="AddHighlight" type="button" /></td>
</tr>
</tbody>
</table>
</div>
<div id="End" class="mainindexTable">
<table width="100%">
<tbody>
<tr>
<td colspan="6" align="left" height="46"><input name="Submit" value="Submit WDR" type="submit" /></td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
<script type="text/javascript" src="Duplicator.js"></script>
</body>
</html>
Code:
function makeDuplicator(button, element, cb_dress, cb_append){
var prototype = element.cloneNode(true);
button.onclick = function(){
//Dress the clone.
var clone = (cb_dress || lazy)(prototype.cloneNode(true));
//Append the clone.
if(cb_append) //Native objects apparently don't like short-circuit operators.
cb_append(clone, element);
else
element.parentNode.appendChild(clone);
};
function lazy(e){
return e;
}
}
var element = document.getElementById('DOandHours').getElementsByTagName('table')[0].rows[1];
makeDuplicator(document.getElementById('AddDO'), element);
function dressHighlight(clone){
//Get rid of the button.
clone.deleteCell(2);
//Blank the text input in case the page was refreshed.
clone.cells[0].getElementsByTagName('input')[0].value = '';
return clone;
};
//The callback (below) won't do this because it never sees the original DIV.
var addHighlight = document.getElementById('AddHighlight');
makeDuplicator(addHighlight, addHighlight.parentNode.parentNode, dressHighlight);
function dressTask(clone){
var table = clone.getElementsByTagName('table')[0];
var highlights = table.rows[4];
//Leave instructions for PHP or it will get confused.
dressTask.index++;
updateNameOf(table.rows[2].cells[0].getElementsByTagName('select')[0]);
updateNameOf(highlights.cells[0].getElementsByTagName('input')[0]);
updateNameOf(highlights.cells[1].getElementsByTagName('select')[0]);
function updateNameOf(element){
element.name = element.id + '[' + dressTask.index + '][]';
}
var addHighlight = highlights.cells[2].getElementsByTagName('input')[0];
makeDuplicator(addHighlight, addHighlight.parentNode.parentNode, dressHighlight);
return clone;
};
dressTask.index = 0;
//This is a more complex appendage, so we'll handle it.
function appendTask(clone, element){
element.parentNode.insertBefore(clone, document.getElementById('End'));
}
makeDuplicator(document.getElementById('AddTask'), document.getElementById('TaskAndHighlights'), dressTask, appendTask);
Bookmarks