1

I am trying to implement the following functionality to add more rows

enter image description here

but I am having a hard time figuring out how to to make the javascript call

<button onclick="buildTable(?????)"><i class="glyphicon glyphicon-plus"></i></button>   

The current number of rows is stored in a PHP variable $rows which was passed in on the previous buildTable(1) call

I need to add $rows to the value from the input box below (the lower '8' as seen below)

<input type="number" placeholder="1" name="moreRows">

How can I add $rows to moreRows and pass it in to the call?

1 Answer 1

1

Use getElementsByName() to find the input element, get its value, and add that to the PHP variable.

<button onclick="buildTable(<?php echo $rows; ?> + parseInt(document.getElementsByName('moreRows')[0].value, 10))"><i class="glyphicon glyphicon-plus"></i></button>   
Sign up to request clarification or add additional context in comments.

2 Comments

What does the [0] mean?
getElementsByName returns a list of all the elements with the name. [0] accesses the first element of the list.

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.