I have a script in which I would like new code to appear based on the response to a question. I am using 'onChange' to trigger the event.
The difficulties I am having are that:
1) The format of the form changes after the event. I would like the new question to be identical the other questions in the form. The text is not center aligned and the input box is smaller and not aligned.
2) I am using PHP to process the form and I prepopulate the fields if the form has already been submitted. The code for population is visible text when it shouldn't be.
Here is the code for a test program.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dom Test</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">
</head>
<script language="javascript" type="text/javascript">
function addRow() {
var bdy = document.getElementsByTagName("body")[0];
var tbl = document.getElementsByTagName("table")[0];
var tblbdy = document.getElementsByTagName("tbody")[0];
var tblrow = document.getElementsByTagName("tr")[3];
row = document.createElement("tr"); row.setAttribute("height", "50");
cell1 = document.createElement("td"); cell1.setAttribute("width", "350"); cell1.setAttribute("align", "center");
text1 = document.createTextNode("Estimated Exempt Interest Income: ");
cell1.appendChild(text1);
cell2 = document.createElement("td"); cell2.setAttribute("width", "350"); cell2.setAttribute("align", "center");
cell3 = document.createElement("input");
cell3.setAttribute("style", "font-size:12pt");
cell3.setAttribute("size", "15");
cell3.setAttribute("type", "text");
cell3.setAttribute("name", "exempt");
cell3.setAttribute("value", "<?php if (isset($_POST['exempt'])) {echo $_POST['exempt'];} ?>");
cell2.appendChild(cell3);
row.appendChild(cell1);
row.appendChild(cell2);
tblbdy.appendChild(row);
tbl.appendChild(tblbdy);
bdy.appendChild(tbl);
tbl.setAttribute("align", "center");
}
</script>
<body>
<p> </p>
<form method=post name="taxform1" >
<table width=600 align="center">
<tr colspan="2"><td>
<p><span style="font-family:times new roman; font-size:18pt; color:black; text-align:center">Income Tax Calculator for Complex Returns</span></p>
</td></tr>
<tr><td><p> </p></td></tr>
<tr>
<td>Estimated Social Security Income: </td>
<td>
<input style="font-size:12pt" type="text" name="ssi" size="15" onChange="javascript:addRow()">
</td>
</tr>
<tr>
<td>Estimated Exempt Interest Income: </td>
<td>
<input style="font-size:12pt" type="text" name="exempt" size="15">
</td>
</tr>
</table>
</form>
</body>
</html>
The new row is the same as the last row in the table. I keep it in so I can compare the two. What JS code do I need to make the program do as I would like it to do?
Thanks in advance for your help.