Getting Value of Table Cell to Depend on which Radio Buttons were Clicked

ChippeRockTheMurph

I have some radio buttons, 10 in the first 5 cells of the row, which I would like to affect the value of the 6th cell in the row, for example, if the radio buttons '6, 7, 5, 8, 7' were clicked for each of the cells it would show the value 33, which is the sum of all 5 of those numbers, in the 'Overall' cell, here is my code so far: BTW you have to see the results of the snippet in full page or it won't look correct.

	// Save's the things the user entered
	document.getElementById('things').addEventListener('blur', function ( evt ) {
		window.localStorage['things-to-be-picked'] = this.value
	})

	// use the user’s saved things
	document.addEventListener('DOMContentLoaded', function ( evt ) {
		var things = window.localStorage['things-to-be-picked']
		if ( things ) {
			document.getElementById('things').value = things
		}
	})
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 95%;
}
td,
th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
  text-align: center
}
tr:nth-child(even) {
  background-color: #dddddd;
}
<table align=center>
<thead>
  <tr>
    <th>Skating</th>
    <th>Shooting</th>
    <th>Passing</th>
    <th>Puck Control</th>
    <th>Team Play</th>
    <th>Overall</th>
  </tr>
</thead>
<tbody>
     <tr>
    <td>
    <form action="">
      <input type="radio"> 1
      <input type="radio"> 2
      <input type="radio"> 3
      <input type="radio"> 4
      <input type="radio"> 5<br>
      <input type="radio"> 6
      <input type="radio"> 7
      <input type="radio"> 8
      <input type="radio"> 9
      <input type="radio">10
    </form>
</td>
<td>
<form action="">
  <input type="radio"> 1
  <input type="radio"> 2
  <input type="radio"> 3
  <input type="radio"> 4
  <input type="radio"> 5<br>
  <input type="radio"> 6
  <input type="radio"> 7
  <input type="radio"> 8
  <input type="radio"> 9
  <input type="radio">10
</form>
</td>
<td>
<form action="">
  <input type="radio"> 1
  <input type="radio"> 2
  <input type="radio"> 3
  <input type="radio"> 4
  <input type="radio"> 5<br>
  <input type="radio"> 6
  <input type="radio"> 7
  <input type="radio"> 8
  <input type="radio"> 9
  <input type="radio">10
</form>
</td>
<td>
<form action="">
  <input type="radio"> 1
  <input type="radio"> 2
  <input type="radio"> 3
  <input type="radio"> 4
  <input type="radio"> 5<br>
  <input type="radio"> 6
  <input type="radio"> 7
  <input type="radio"> 8
  <input type="radio"> 9
  <input type="radio">10
</form>
</td>
<td>
<form action="">
  <input type="radio"> 1
  <input type="radio"> 2
  <input type="radio"> 3
  <input type="radio"> 4
  <input type="radio"> 5<br>
  <input type="radio"> 6
  <input type="radio"> 7
  <input type="radio"> 8
  <input type="radio"> 9
  <input type="radio">10
</form>
</td>
<td>
</td>
</tr>
</tr>
</tbody>
</table>

happymacarts

If you want only one value to be able to be selected on a radio group they all need to have the same name /per group More Info

I used jQuery for this since you had it tagged.

The <form> elements are not needed but i left them in place in case you need them for another purpose

I modified this to support multiple rows by adding the class="item" to each <tr> I assume you plan to populate this info from a db or some automated loop the data-id attribute could be used also to capture unique info for each row should you need to target them uniquely later

$(document).ready(function() {
  $(':radio').change(function() {
    var row = $(this).closest('.item'); 
    var checkedItems = row.find(":checked")
    if (checkedItems.length > 4) {
      row.find("td.overall").html(getOvarall(checkedItems));
    }
  })

  function getOvarall(_checkedItems) {
    var total = 0;
    _checkedItems.each(function() {
      total += parseFloat($(this).val());
    });
    return total;
  }


});
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 95%;
}
td,
th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
  text-align: center
}
tr:nth-child(even) {
  background-color: #dddddd;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table align=center>
  <thead>
    <tr>
      <th>Skating</th>
      <th>Shooting</th>
      <th>Passing</th>
      <th>Puck Control</th>
      <th>Team Play</th>
      <th>Overall</th>
    </tr>
  </thead>
  <tbody>
    <tr class="item" data-id="1">
      <td>
        <form action="">
          <input type="radio" name="skating" value="1">1
          <input type="radio" name="skating" value="2">2
          <input type="radio" name="skating" value="3">3
          <input type="radio" name="skating" value="4">4
          <input type="radio" name="skating" value="5">5
          <br>
          <input type="radio" name="skating" value="6">6
          <input type="radio" name="skating" value="7">7
          <input type="radio" name="skating" value="8">8
          <input type="radio" name="skating" value="9">9
          <input type="radio" name="skating" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="shooting" value="1">1
          <input type="radio" name="shooting" value="2">2
          <input type="radio" name="shooting" value="3">3
          <input type="radio" name="shooting" value="4">4
          <input type="radio" name="shooting" value="5">5
          <br>
          <input type="radio" name="shooting" value="6">6
          <input type="radio" name="shooting" value="7">7
          <input type="radio" name="shooting" value="8">8
          <input type="radio" name="shooting" value="9">9
          <input type="radio" name="shooting" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="passing" value="1">1
          <input type="radio" name="passing" value="2">2
          <input type="radio" name="passing" value="3">3
          <input type="radio" name="passing" value="4">4
          <input type="radio" name="passing" value="5">5
          <br>
          <input type="radio" name="passing" value="6">6
          <input type="radio" name="passing" value="7">7
          <input type="radio" name="passing" value="8">8
          <input type="radio" name="passing" value="9">9
          <input type="radio" name="passing" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="puck_control" value="1">1
          <input type="radio" name="puck_control" value="2">2
          <input type="radio" name="puck_control" value="3">3
          <input type="radio" name="puck_control" value="4">4
          <input type="radio" name="puck_control" value="5">5
          <br>
          <input type="radio" name="puck_control" value="6">6
          <input type="radio" name="puck_control" value="7">7
          <input type="radio" name="puck_control" value="8">8
          <input type="radio" name="puck_control" value="9">9
          <input type="radio" name="puck_control" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="team_play" value="1">1
          <input type="radio" name="team_play" value="2">2
          <input type="radio" name="team_play" value="3">3
          <input type="radio" name="team_play" value="4">4
          <input type="radio" name="team_play" value="5">5
          <br>
          <input type="radio" name="team_play" value="6">6
          <input type="radio" name="team_play" value="7">7
          <input type="radio" name="team_play" value="8">8
          <input type="radio" name="team_play" value="9">9
          <input type="radio" name="team_play" value="10">10
        </form>
      </td>
      <td class="overall">
      </td>

    </tr>
    <tr class="item" data-id="2">
      <td>
        <form action="">
          <input type="radio" name="skating" value="1">1
          <input type="radio" name="skating" value="2">2
          <input type="radio" name="skating" value="3">3
          <input type="radio" name="skating" value="4">4
          <input type="radio" name="skating" value="5">5
          <br>
          <input type="radio" name="skating" value="6">6
          <input type="radio" name="skating" value="7">7
          <input type="radio" name="skating" value="8">8
          <input type="radio" name="skating" value="9">9
          <input type="radio" name="skating" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="shooting" value="1">1
          <input type="radio" name="shooting" value="2">2
          <input type="radio" name="shooting" value="3">3
          <input type="radio" name="shooting" value="4">4
          <input type="radio" name="shooting" value="5">5
          <br>
          <input type="radio" name="shooting" value="6">6
          <input type="radio" name="shooting" value="7">7
          <input type="radio" name="shooting" value="8">8
          <input type="radio" name="shooting" value="9">9
          <input type="radio" name="shooting" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="passing" value="1">1
          <input type="radio" name="passing" value="2">2
          <input type="radio" name="passing" value="3">3
          <input type="radio" name="passing" value="4">4
          <input type="radio" name="passing" value="5">5
          <br>
          <input type="radio" name="passing" value="6">6
          <input type="radio" name="passing" value="7">7
          <input type="radio" name="passing" value="8">8
          <input type="radio" name="passing" value="9">9
          <input type="radio" name="passing" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="puck_control" value="1">1
          <input type="radio" name="puck_control" value="2">2
          <input type="radio" name="puck_control" value="3">3
          <input type="radio" name="puck_control" value="4">4
          <input type="radio" name="puck_control" value="5">5
          <br>
          <input type="radio" name="puck_control" value="6">6
          <input type="radio" name="puck_control" value="7">7
          <input type="radio" name="puck_control" value="8">8
          <input type="radio" name="puck_control" value="9">9
          <input type="radio" name="puck_control" value="10">10
        </form>
      </td>
      <td>
        <form action="">
          <input type="radio" name="team_play" value="1">1
          <input type="radio" name="team_play" value="2">2
          <input type="radio" name="team_play" value="3">3
          <input type="radio" name="team_play" value="4">4
          <input type="radio" name="team_play" value="5">5
          <br>
          <input type="radio" name="team_play" value="6">6
          <input type="radio" name="team_play" value="7">7
          <input type="radio" name="team_play" value="8">8
          <input type="radio" name="team_play" value="9">9
          <input type="radio" name="team_play" value="10">10
        </form>
      </td>
      <td class="overall">
      </td>

    </tr>
  </tbody>
</table>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting the value of "on" for radio buttons

Save clicked value of a cell of a table

Getting only first value of a button clicked which has multiple buttons with multiple values

Getting Table View Cell text Value in Searchbar Placeholder once a specified cell is clicked

ngIf is not working on getting value from radio buttons

Getting value of multiple radio buttons groups javascript

Getting DataRow value from cell clicked (RadGridView)

Disable Radio Buttons If Table Value Is 1 or more

Trying to output value of radio buttons in table list

Simple javascript to know which cell in table cell clicked

Getting radio button value when button is clicked is not working angularjs

why the button inside a table cell which is clicked is undefined

How to detect which table cell is clicked in swift 2

Show the order at which buttons are clicked

radio button as table cell

Javascript all buttons not getting clicked

Getting checked radio buttons values

getting multiple radio buttons in rails

How to get the value from a cell when table row is clicked

Read table header value from the chosen (clicked) cell

How to insert selected radio button value into table cell

Get the value of a clicked cell

JQUERY - Getting data in a table cell which has a specific class

Detect which `View` was clicked on a `Cell`

State will not remain for radio buttons once clicked React

Preventing radio buttons from being clicked completely

Calculation of Inputted Values When Radio Buttons Are Clicked

How do you find the radio buttons not clicked?

jQueryMobile radio buttons when clicked generates errors