15. oktober 2003 - 10:00
Der er
4 kommentarer og 1 løsning
Skjul/vis tabelelementer efter valg i select tag
Hej med jer. Jeg håber en eller anden kan provide en løsning på følgende: Pr. default er værdien "Option 1" valgt i feltet "Field name #3". Hermed er også "Field name #4" + de to radiobuttons + de to multiple selects nedenunder vist. Jeg vil gerne have det således, at når man i "Field name #3" vælger "Option 2", så skjules "Field name #4" + de to radiobuttons + de to multiple selects. Når man så vælger "Option 1" i "Field name #3" skal "Field name #4" + de to radiobuttons + de to multiple selects skjules. Kan nogen hjælpe? Koden er her: <html> <head> <title>Hide/Show Test</title> <style> td.input, select.input, input { font-family: arial; font-size: 12px; } td.xs { font-family: verdana; font-size: 9px; } </style> </head> <body bgcolor="#ffffff"> <table width="500" cellpadding="5" cellspacing="0" border="1"> <form name="" method="post" action=""> <tr> <td> <table width="100%" cellspacing="0" cellpadding="3" border="0"> <tr> <td width="135" class="input"><div align="left">Field name #1</div></td> <td width="110"><input class="input" class="input" maxlength="16" style="width: 160px;"></td> <td colspan="2"></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #2</div></td> <td width="110"><input class="input" class="input" maxlength="16" style="width: 160px;"></td> <td colspan="2"></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #3</div></td> <td class="s"> <select name="" id="" class="input" style="width: 80px;"> <option value="1">Option 1</option> <option value="1">Option 2</option> </select> </td> <td colspan="2"></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #4</div></td> <td align="left" class="xs" valign="center" colspan="3"> <input class="input" value="" name="" type="radio">Used by all <input class="input" value="" name="" type="radio" checked>Used only by the following </td> </tr> <tr> <td width="135" class="input"></td> <td align="left" class="s" width="150" valign="middle"> <select size="8" style="width:155px;" class="input" multiple> <option>USED_BY_NAME_01</option> <option>USED_BY_NAME_02</option> <option>USED_BY_NAME_03</option> <option>USED_BY_NAME_04</option> <option>USED_BY_NAME_05</option> <option>USED_BY_NAME_06</option> <option>USED_BY_NAME_07</option> <option>USED_BY_NAME_08</option> <option>USED_BY_NAME_09</option> </select> </td> <td align="left" class="input" width="30" valign="top"> <input type="button" style="width:25px;" name="Add" value="»"><br> <input type="button" style="width:25px;" name="Remove" value="«"> </td> <td align="left" class="m" valign="middle" width="150"> <select size="8" style="width:155px;" class="input" multiple> </select> </td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #5</div></td> <td colspan="3" align="left"> <select name="" id="" class="input" style="width: 80px;"> <option value="1">Open</option> <option value="1">Closed</option> </select> </td> </tr> </table> </td> </tr> </table> </body> </html>
Annonceindlæg fra Infor
15. oktober 2003 - 10:16
#1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Hide/Show Test</title> <script language="JavaScript" type="text/javascript"> function showHide(sel){ sh=(sel==2)?"none":""; for(i=1;i<=6;i++){ document.getElementById('4_'+i).style.display=sh; } } </script> <style> td.input, select.input, input { font-family: arial; font-size: 12px; } td.xs { font-family: verdana; font-size: 9px; } </style> </head> <body bgcolor="#ffffff"> <table width="500" cellpadding="5" cellspacing="0" border="1"> <form name="" method="post" action=""> <tr> <td> <table width="100%" cellspacing="0" cellpadding="3" border="0"> <tr> <td width="135" class="input"><div align="left">Field name #1</div></td> <td width="110"><input class="input" class="input" maxlength="16" style="width: 160px;"></td> <td colspan="2"></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #2</div></td> <td width="110"><input class="input" class="input" maxlength="16" style="width: 160px;"></td> <td colspan="2"></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #3</div></td> <td class="s"> <select name="" id="" class="input" style="width: 80px;" onChange="showHide(this.options[this.selectedIndex].value);"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> </td> <td colspan="2"></td> </tr> <tr> <td width="135" class="input"><div id="4_1">Field name #4</div></td> <td align="left" class="xs" valign="center" colspan="3"> <div id="4_2"> <input class="input" value="" name="" type="radio"> Used by all <input class="input" value="" name="" type="radio" checked> Used only by the following </div></td> </tr> <tr> <td width="135" class="input"><div id="4_3"></div></td> <td align="left" class="s" width="150" valign="middle"> <div id="4_4"> <select size="8" style="width:155px;" class="input" multiple> <option>USED_BY_NAME_01</option> <option>USED_BY_NAME_02</option> <option>USED_BY_NAME_03</option> <option>USED_BY_NAME_04</option> <option>USED_BY_NAME_05</option> <option>USED_BY_NAME_06</option> <option>USED_BY_NAME_07</option> <option>USED_BY_NAME_08</option> <option>USED_BY_NAME_09</option> </select> </div></td> <td align="left" class="input" width="30" valign="top"> <div id="4_5"> <input type="button" style="width:25px;" name="Add" value="»"> <br> <input type="button" style="width:25px;" name="Remove" value="«"> </div></td> <td align="left" class="m" valign="middle" width="150"> <div id="4_6"> <select size="8" style="width:155px;" class="input" multiple> </select> </div></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #5</div></td> <td colspan="3" align="left"> <select name="" id=" class="input" style="width: 80px;"> <option value="1">Open</option> <option value="1">Closed</option> </select> </td> </tr> </table> </td> </tr> </table> </body> </html>
15. oktober 2003 - 11:41
#2
Umiddelbart virker det fint nok. Men når man vælger "Option 2" i select boksen og elementerne nedenunder bliver skjult ændrer bredden på feltnavnene ("Field name #1 osv) sig. De bliver lidt bredere, og når man skifter tilbage igen ved at vælge "Option 1" bliver de den oprindelige bredde. Hvorfor katten gør de det?
15. oktober 2003 - 12:09
#3
fordi der var uoverenstemmelser i breddeangivelserne i dine tabeller sådan: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Hide/Show Test</title> <script language="JavaScript" type="text/javascript"> function showHide(sel){ sh=(sel==2)?"none":""; document.getElementById('sh_row1').style.display=sh; document.getElementById('sh_row2').style.display=sh; } </script> <style> td.input, select.input, input { font-family: arial; font-size: 12px; } td.xs { font-family: verdana; font-size: 9px; } </style> </head> <body bgcolor="#ffffff"> <table width="600" cellpadding="5" cellspacing="0" border="1"> <form name="" method="post" action="#"> <tr> <td> <table width="100%" cellspacing="0" cellpadding="3" border="0"> <tr> <td width="135" class="input"><div align="left">Field name #1</div></td> <td width="165"><input class="input" maxlength="16" style="width: 160px;"></td> <td colspan="2"> </td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #2</div></td> <td width="165"><input class="input" maxlength="16" style="width: 160px;"></td> <td colspan="2"> </td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #3</div></td> <td width="165" class="s"> <select name="" id="" class="input" style="width: 80px;" onChange="showHide(this.options[this.selectedIndex].value);"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select></td> <td colspan="2"> </td> </tr> <tr id="sh_row1"> <td width="135" class="input">Field name #4</td> <td align="left" class="xs" valign="center" colspan="3"> <input class="input" value="" name="" type="radio"> Used by all <input class="input" value="" name="" type="radio" checked> Used only by the following </td> </tr> <tr id="sh_row2"> <td width="135" class="input"> </td> <td align="left" class="s" width="165" valign="middle"> <select size="8" style="width:155px;" class="input" multiple> <option>USED_BY_NAME_01</option> <option>USED_BY_NAME_02</option> <option>USED_BY_NAME_03</option> <option>USED_BY_NAME_04</option> <option>USED_BY_NAME_05</option> <option>USED_BY_NAME_06</option> <option>USED_BY_NAME_07</option> <option>USED_BY_NAME_08</option> <option>USED_BY_NAME_09</option> </select></td> <td align="left" class="input" width="30" valign="top"> <input type="button" style="width:25px;" name="Add" value="»"> <br> <input type="button" style="width:25px;" name="Remove" value="«"></td> <td align="left" class="m" valign="middle"> <select size="8" style="width:155px;" class="input" multiple> </select></td> </tr> <tr> <td width="135" class="input"><div align="left">Field name #5</div></td> <td colspan="3" align="left"> <select name="" id="" class="input" style="width: 80px;"> <option value="1">Open</option> <option value="1">Closed</option> </select></td> </tr> </table> </td> </tr> </form> </table> </body> </html>