Link to home
Start Free TrialLog in
Avatar of freezegravity
freezegravity

asked on

Changing orientation of a table

Hello Experts:

I have a table like this:

-------------------------
<table id="col_head">
   <caption> This is a table oriented one way</caption>
   <tr>
          <td>Empty cell</td>
          <th>Column Header 1</th>
          <th>Column Header 2</th>
          <th>Column Header 3</th>
   </tr>
   <tr>
          <th>Row Header 1</th>
          <td>Value 1</td>
          <td>Value 2</td>
          <td>Value 3</td>
   </tr>
</table>
<button name="submit" value="change table view" onsubmit="">

--------------------

Now, after the button is clicked, I want the resultant html to be:

--------------------
<table id="row_head">
    <tr>
          <td>Empty Cell</td>
          <th>Row Header 1</th>
    </tr>
    <tr>
          <th>Column Header 1</th>
          <td>Value 1</td>
    </tr>
    <tr>
           <th>Column Header 2</th>
           <td>Value 2</td>
    </tr>
    <tr>
            <th>Column Header 3</th>
            <td>Value 3</td>
    </tr>
</table>
----------------------
Avatar of freezegravity
freezegravity

ASKER

Oh and for id="row_head", the caption should say <caption>This is a table oriented another way</caption>

Also, the ideal solution would not be concerned with the amount of "column headers" and "row headers."

And another thing, it might be easier to put a border="1" on the table definition just so you can better determine what I am trying to do.

Thanks again.

FG!

SOLUTION
Avatar of enachemc
enachemc
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh well, i forgot:

4.) it *only* works with TDs. THs or TFs are not recognized. this would intensify the code significantly, while not using header or footer cells wouldnt really impact i think.

but it really works for *any* table structure. try it with 20 rows and 5 columns orso...
AmigoJack and enachemc:

WOW!!!!

I didn't think I would receive code/solution that is this efficient and effective.

If ever I've seen a split points questions, it is this. I wanted to point out the differences between the code for future readers who will no doubt benefit if they find this question:

AmigoJack's code:

1. Really works for tables with any amount of row's/column's.
2. Doesn't take into account th's and other tags.
3. Works with all browsers.

enachemc's code:

1. Takes into account th's and other tags
2. Does NOT in and of itself figure out how many columns/rows there are. It is easily configurable for any amount though, but for every extra row, one must code one more line.

Both have their advantages and disadvantages.  Both shall be tremendously helpful!

Thanks a bunch you two!

FG!
Correction:

enachemc's code turns th's to td's.

AmigoJack's code doesn't have th's to start with.

I hope that I will get a chance to modify your codes so that th's are accounted for. I shall try and post here when done and tested.

Thanks again.

FG!
good luck :)