Connecting Tech Pros Worldwide Forums | Help | Site Map

Show-hide table content wrapping

Newbie
 
Join Date: May 2007
Posts: 2
#1: May 4 '07
Hi All,

I have a problem with some javascript code.

I am trying to toggle display between two tables upon change of a select box ( to alternate between search forms)

eg. one called searchTableUS (displayed when USA is selected) and searchTableCA when (displayed when canada is selected)

Expand|Select|Wrap|Line Numbers
  1. <table  id="searchTableUS">
  2. <tr>
  3. <td>
  4.   <label class="required">Check-in:</label></td>
  5. <td id="checkIn">
  6.   <select name="check-inMonthYear">
  7.     <option value="10">Jan 2006</option>
  8.   </select>                            
  9.   <select name="check-inDay">
  10.     <option value="10">Tue 10</option>
  11.   </select>
  12. </td>
  13. </tr>
  14. </table>
  15.  
  16. <table  id="searchTableCA">
  17. <tr>
  18. <td>
  19.   <label class="required">Check-in:</label></td>
  20. <td id="checkIn">
  21.   <select name="check-inMonthYear">
  22.     <option value="10">Jan 2006</option>
  23.   </select>                            
  24.   <select name="check-inDay">
  25.     <option value="10">Tue 10</option>
  26.   </select>
  27. </td>
  28. </tr>
  29. </table>
CSS:

Expand|Select|Wrap|Line Numbers
  1. table.showMe,table.showMe select{
  2.     display:block;    
  3. }
  4. table.hideMe,table.hideMe select{
  5.     display:none;
  6. }
Javascript (called onChange of select box and passes the object):

Expand|Select|Wrap|Line Numbers
  1. function swapSimpleSearch(obj){
  2.  var selectedCountry = obj.options[obj.selectedIndex].value;    //get selection
  3.  if (selectedCountry == "CA"){
  4.    document.getElementById("searchTableUS").className = "hideMe";
  5.    document.getElementById("searchTableCA").className = "showMe";
  6.  }
  7.  else{
  8.    document.getElementById("searchTableCA").className = "hideMe";
  9.    document.getElementById("searchTableUS").className = "showMe";
  10.  }        
  11. }
The problem I am having is when the hidden table is displayed, the select boxes are wrapping underneath each other instead of on the same line in the <TD>. I know its not the html as when the page first loads it looks fine. Its only when you hide it and display it again. Is there a known issue with hide/showing tables and content wrapping?

I tried adding nowrap to the td and white-space in CSS but both don't work.

Any ideas??

Thanks in advance,
Lisa

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: May 4 '07

re: Show-hide table content wrapping


Try giving the td width.
Reply