Skip to content

Commit

Permalink
replace calculate button by listening to all input changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasHuber committed Jun 9, 2024
1 parent 44f4ef8 commit c3bfc79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ <h2>2. Enter the details for your desired tuning:</h2>
</tfoot>
</table>
</div>
<button id="calculate">Calculate</button>
</div>
</div>
<p>Thanks for using my app! <br> If you like it and have a (remote) job for me or want to see me play, here are my socials:<br>
Expand Down
10 changes: 9 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
function setupInputListeners() {
document.querySelectorAll('input').forEach(input => {
input.addEventListener('input', calculate);
});
}

function addRemoveButtonListener(button) {
button.addEventListener('click', function() {
const row = this.closest('tr');
Expand Down Expand Up @@ -48,6 +54,7 @@ function addString(position) {
stringsContainer.insertBefore(newStringRow, position === 'start' ? stringsContainer.firstChild.nextSibling : stringsContainer.lastChild);

addRemoveButtonListener(newStringRow.querySelector('.remove-string'));
setupInputListeners(); // Set up listeners for the new inputs
}

function calculate() {
Expand Down Expand Up @@ -123,4 +130,5 @@ document.querySelector('.add-front').addEventListener('click', function() {
addString('start');
});

document.getElementById('calculate').addEventListener('click', calculate);
calculate();
setupInputListeners();
4 changes: 0 additions & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ button:hover {
background: #a7a7a7;
}

#calculate {
border: 1px solid #ddd;
}

table {
width: 100%;
max-width: 1024px;
Expand Down

0 comments on commit c3bfc79

Please sign in to comment.