Code:
<!DOCTYPE html><!-- Standards invoking DOCTYPE required for IE 8, perhaps others -->
<html>
<head>
<title>Car Design</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function configureDropDownLists(ddl, doc_sys) {
(doc_sys = document.getElementsByName('doc' + doc_sys + '_sys')[0]).options.length = 0;
var options = configureDropDownLists.options[ddl.value.toLowerCase()], i = -1;
if(options){ while (++i < options.length) { createOption(doc_sys, options[i]); } }
}
configureDropDownLists.options = {
e1: ['Bilge & Ballast (BL)', 'Boiler (B)', 'Vents & Sounds (V)', 'Other (GENR)'],
e2: ['One Line Diagram (ONE)', 'Sound Powered Phone (SPP)', 'Other (GENR)'],
h1: ['Damage Stability (DAM)', 'Intact Stability (INT)', 'Lightship (LTSH)', 'Other (GENR)']
};
function createOption(ddl, text, value) {
ddl.options.add(new Option(text, value || text));
}
function adddocs(num){
adddocs.docs = adddocs.docs || [document.getElementById('doc1')];
var numdocs = adddocs.docs.length, newdoc, lastdoc, needed, newinputs, input, newel, oldel, newselects, select;
if(num < 1){num = 1;}
if(num < numdocs){
--num;
while(--numdocs > num){
(lastdoc = adddocs.docs[numdocs]).parentNode.removeChild(lastdoc);
adddocs.docs.splice(numdocs, 1);
}
} else if (num > numdocs) {
needed = num - numdocs;
while(--needed > -1){
newdoc = adddocs.docs[0].cloneNode(true);
adddocs.docs.push(newdoc);
numdocs = adddocs.docs.length;
newdoc.id = 'doc' + numdocs;
newinputs = newdoc.getElementsByTagName('input');
input = newinputs.length;
while(--input > -1){
if((newel = newinputs[input]).type === 'text'){
newel.name = newel.name.replace('1', numdocs);
newel.value = '';
} else if ((oldel = newinputs[input]).type === 'file'){
newel = document.createElement('input');
newel.type = 'file';
newel.name = oldel.name.replace('1', numdocs);
newel.setAttribute('allow', oldel.getAttribute('allow'), 0);
newel.size = oldel.size;
oldel.parentNode.replaceChild(newel, oldel);
}
}
newselects = newdoc.getElementsByTagName('select');
select = newselects.length;
while(--select > -1){
newel = newselects[select];
if(newel.name === 'doc1_type'){
newel.options.selectedIndex = 0;
} else if (newel.name === 'ddl1'){
try{newel.removeAttribute('onchange', 0);}catch(e){}
newel.onchange = function(){};
newel.options.selectedIndex = 0;
newel.onchange = (function(newel, numdocs){
return function(){
configureDropDownLists(newel, numdocs);
};
})(newel, numdocs);
} else if (newel.name === 'doc1_sys'){
newel.options.length = 0;
}
if(newel.name){newel.name = newel.name.replace('1', numdocs);}
}
newdoc.firstChild.nodeValue = newdoc.firstChild.nodeValue.replace('1', numdocs);
(lastdoc = adddocs.docs[numdocs - 2]).parentNode.insertBefore(newdoc, lastdoc.nextSibling);
}
}
}
function resetassist(){
adddocs(1);
document.getElementsByName('doc1_sys')[0].options.length = 0;
}
</script>
</head>
<body>
<form name="car" action="html_form_action.asp" method="get">
Submissions:<br>
Number of Files to Attach: <select name="numberoffiles" onchange="adddocs(this.value);">
<option value="0">0</option>
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select> Expedite? <input type="radio" name="nvic" value="Yes">Yes <input type="radio" name="nvic" value="No" checked>No
<br>
<!-- Begin what's dynamically added with each "number of files" -->
<div id="doc1">Document 1:<br><!-- there can be no space, line break, or tag between <div id="doc1"> and the text "Document 1:" -->
<table>
<tr>
<td>Name:</td>
<td><input type="text" size="60" name="doc1_name"></td>
<td><input type="file" name="doc1_file" size="72" allow="text"></td>
</tr>
<tr>
<td>Number:</td>
<td><input type="text" name="doc1_number"> Rev.: <input type="text" size="2" maxlength="2" name="doc1_rev"> Type: <select name="doc1_type">
<option value="Letter">Letter</option>
<option value="Manual">Manual</option>
<option value="Plans">Plans</option></select></td>
<td>Branch: <select name="ddl1" onchange="configureDropDownLists(this, 1)">
<option value=""></option>
<option value="E2">Electrical</option>
<option value="H1">Hull & Stability</option>
<option value="E1">Machinery & Piping</option>
</select>
System:
<select name="doc1_sys">
</select></td>
</tr>
</table>
<br>
</div>
<!-- End what's dynamically added with each "number of files" -->
<br>
<input type="reset" value="Clear" onclick="resetassist(); return true;">
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
document.forms.car.reset();
resetassist();
</script>
</body>
</html>
Bookmarks