superjoepsu
05-12-2008, 05:09 PM
I've searched these forums and spent some time on Google, but can't seem to find a direct solution to what I am trying to achieve. Basically I have a drop-down menu that should add/remove a table row with HTML form elements based upon selection criteria. The caveat to this is that I need to have control over where the row appears, rather than automatically appended to the end.
I found an example on this site that almost does what I need it to do. However, I need to generate the entire row, which doesn't seem to work nicely with the span tag in the example. The only way I can get it to semi-do what I need is by actually creating that row in the HTML and dropping the <span> tags in the <td> cells, but only populating it based upon drop-down selection criteria. This creates a visual problem as the row still shows up in the browser.
Also, this script doesn't remove the added row if you go back to the default selection. And does anybody know why IE7 and Safari use the excess padding in that table cell when I use the <form> tag? FF seems to work fine with it.
Here is my current working 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>Untitled Document</title>
<script type="text/javascript">
<!--
function writebox(form){
if(form.menu1.value=="1"){
document.getElementById('thebox1').innerHTML='Option 1a';
document.getElementById('thebox2').innerHTML='Option 1b';
}
else if(form.menu1.value=="2"){
document.getElementById('thebox1').innerHTML='Option 2a';
document.getElementById('thebox2').innerHTML='Option 2b';
}
else if(form.menu1.value=="3"){
document.getElementById('thebox1').innerHTML='Option 3a';
document.getElementById('thebox2').innerHTML='Option 3b';
}
}
//-->
</script>
</head>
<body>
<table width="50%" border="1" cellpadding="0" align="center">
<tr>
<td width="50%">
<form>
<select name="menu1" onchange="writebox(this.form)">
<option value="none" selected></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
</td>
<td width="50%">Cell 1</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
<tr>
<td><span id="thebox1"></span></td>
<td><span id="thebox2"></span></td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
</table>
</body>
</html>
Thank you!
I found an example on this site that almost does what I need it to do. However, I need to generate the entire row, which doesn't seem to work nicely with the span tag in the example. The only way I can get it to semi-do what I need is by actually creating that row in the HTML and dropping the <span> tags in the <td> cells, but only populating it based upon drop-down selection criteria. This creates a visual problem as the row still shows up in the browser.
Also, this script doesn't remove the added row if you go back to the default selection. And does anybody know why IE7 and Safari use the excess padding in that table cell when I use the <form> tag? FF seems to work fine with it.
Here is my current working 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>Untitled Document</title>
<script type="text/javascript">
<!--
function writebox(form){
if(form.menu1.value=="1"){
document.getElementById('thebox1').innerHTML='Option 1a';
document.getElementById('thebox2').innerHTML='Option 1b';
}
else if(form.menu1.value=="2"){
document.getElementById('thebox1').innerHTML='Option 2a';
document.getElementById('thebox2').innerHTML='Option 2b';
}
else if(form.menu1.value=="3"){
document.getElementById('thebox1').innerHTML='Option 3a';
document.getElementById('thebox2').innerHTML='Option 3b';
}
}
//-->
</script>
</head>
<body>
<table width="50%" border="1" cellpadding="0" align="center">
<tr>
<td width="50%">
<form>
<select name="menu1" onchange="writebox(this.form)">
<option value="none" selected></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
</td>
<td width="50%">Cell 1</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
<tr>
<td><span id="thebox1"></span></td>
<td><span id="thebox2"></span></td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 1</td>
</tr>
</table>
</body>
</html>
Thank you!