Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

Html table to JSON : including radio button checked values

$
0
0

I have a html table in which there are :

  • rowspans
  • radio buttons of different groups in merged cells

The table looks like :

<table><tr><th>Data1</th><th>Data2</th><th>Data3</th><th>Data4</th><th>Data5</th><th>Data6</th></tr><tr><td rowspan="3" contenteditable="true"><label><input type="radio" value="0" name="typeOf0"> <span>Option 1</span> </label><br><label><input type="radio" value="1" name="typeOf0" checked=""> <span>Option 2</span> </label><br></td><td rowspan="3" contenteditable="true">12313</td><td contenteditable="true">5</td><td contenteditable="true">0</td><td contenteditable="true">0</td><td rowspan="3" contenteditable="true">50</td></tr><tr><td contenteditable="true">0</td><td contenteditable="true">8</td><td contenteditable="true">0</td></tr><tr><td contenteditable="true">0</td><td contenteditable="true">0</td><td contenteditable="true">3</td></tr><tr><td rowspan="3" contenteditable="true"><label><input type="radio" value="0" name="typeOf1" checked=""> <span>Option 1</span> </label><br><label><input type="radio" value="1" name="typeOf1"> <span>Option 2</span> </label><br></td><td rowspan="3" contenteditable="true">46456</td><td contenteditable="true">3</td><td contenteditable="true">0</td><td contenteditable="true">0</td><td rowspan="3" contenteditable="true">110</td></tr><tr><td contenteditable="true">0</td><td contenteditable="true">2</td><td contenteditable="true">0</td></tr><tr><td contenteditable="true">0</td><td contenteditable="true">0</td><td contenteditable="true">9</td></tr></table>

Let's say there is a button:

<button class="btn conPhy" id="convert06Phy">Convert</button>

What I want is, when I click the button the table should be converted to a JSON Format like this below where in radio buttons in each row :

  • 0 = Option 1 is checked and
  • 1 = Option 2 is checked

    var data = [{"Data1": 1,"Data2": 12313,"Data3": [5,0,0],"Data4": [0,8,0],"Data5": [0,0,3],"Data6": 50
    },
    {"Data1": 0,"Data2": 46456,"Data3": [3,0,0],"Data4": [0,2,0],"Data5": [0,0,9],"Data6": 110
    }];

How should I approach to solve this with jQuery?


Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>