0

when I click the button, the value of these both input fields should display in the cells.

<input id="input_for_left_column" placeholder="Minuten" type="number">
<input id="input_for_left_column" placeholder="Minuten" type="number">
<button type="submit" id="submit_for_table">Add</button>

<table class="table">
<tr>
    <td id="left_column"></td>
    <td id="right_column"></td>
</tr>
</table>

<script>
$(function(){
  function add_value() {
    $("#left_column").val($('#input_for_left_column').text(val());
    $("#right_column").val($('#input_for_right_column').text(val());
  }
  $('#submit_for_table').click(add_value);
 });  
 </script>

1 Answer 1

1

To set the text of a table cell you'd use .text() and to get the value of an input you'd use .val()
Also you have input_for_left_column as the id for the two inputs.

$(function(){
  function add_value() {
    $("#left_column").text($('#input_for_left_column').val());
    $("#right_column").text($('#input_for_right_column').val());
  }
  $('#submit_for_table').click(add_value);
 });  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input_for_left_column" placeholder="Minuten" type="number">
<input id="input_for_right_column" placeholder="Minuten" type="number">
<button type="submit" id="submit_for_table">Add</button>

<table class="table">
<tr>
    <td id="left_column"></td>
    <td id="right_column"></td>
</tr>
</table>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.