After spending a whole day trying to get this HTML/java script to work properly, I came across some code online that I used here. My goal is to have the "Colors*" row not displayed when the page loads, but to show the color options when a shirt size is selected from the drop-down menu.
Currently, the color table with radio buttons is not displaying correctly, as it resizes and does not match the length of the row above. I am also struggling with the radio buttons allowing multiple selections instead of just one.
I have also included two images to illustrate the issue. Edit: The button problem has been resolved.
I am looking to achieve this using only JavaScript, without jQuery.
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="jsForm.js"></script>
<title>Javascript with Forms</title>
<style type="text/css">
table{
width: 800px;
padding: 10px;
}
</style>
</head>
<body>
<form action="#">
<table border="1">
<caption>T-Shirt Selection</caption>
<tr><td style="100px;"></td><td style="150px;"></td><td style="50px;"></td><td style="50px;"></td><td></td></tr>
<tr>
<th>Description</th>
<th>Selection</th>
<th>Qty</th>
<th>Total</th>
</tr>
<tr>
<td>
T_Shirt 1:
</td>
<td>
<select id="shirts" onchange="showButton(this)">
<option value="0" selected >Choose T-Shirt </option>
<option value="1" >Small $10.99</option>
<option value="2" >Medium $12.99</option>
<option value="3" >Large $14.99</option>
<option value="4" >X-Large $15.99</option>
<option value="5" >XX-Large $15.99</option>
</select>
</td>
<td>
<input type="text" name="qty" maxlength="4" size="4" />
</td>
<td>
<input type="text" name="qty" maxlength="10" size="10" />
</td>
</tr>
<tr id="hidden_button" style="display:none;">
<td colspan="1">Color.*</td>
<td colspan="3">
<input type="radio" name="Back" value="Black" /> Black
<input type="radio" name="White" value="White" /> White
<input type="radio" name="Blue" value="Blue" /> Blue
<input type="radio" name="Red" value="Red"/> Red
</td>
</tr> </table>
</form>
</body>
Javascript
function showButton(elem){
if(elem.value == 0){
document.getElementById('hidden_button').style.display = "none";
}else if(elem.value > 0){
document.getElementById('hidden_button').style.display = "block";
}
}
Here is an example of the issue: https://i.sstatic.net/RNk1a.png https://i.sstatic.net/wp7b0.png
Any assistance would be greatly appreciated.