I am trying to figure a way where when I input 2 IDs on a form, I want to see the count to display, perhaps in a input field below it. This way it’s a double check for me that I am not transposing numbers and getting the count right.
Good question, I should of mentioned that. Yes, all numeric.
Yes, the count will always start at ID1 with the lowest number and I tab through to ID2, the highest number and what I would like it that after I tab again, it gives me a total before I click a submit button. Purpose, sending emails based on ID’s.
As you tab to the output field (before you click the submit button) don’t you need JS because you are not refreshing the page. It would be easy to do the math on the post page and in fact it does a count. I want a count before I submit it.
I guess you have other <input> elements on your web page and therefore querySelectorAll will need to be more specific to select these three input elements.
Obviously I only need the count on those 2 input fields with the name id1 and id2. Can I replace the word input in the QuerySelectorAll to another name and then I use that name as a class in those 2 input fields?
I am not really sure how to do that, but I am thinking it has to be something like that.
This is not a big deal, but I wanted to know how to do the math in the subtract function for this reason:
When you take 2 numbers and subtract them from each other you are not counting the last one. For example, if I have 1 in id1 and 10 in id2, 10 - 1 = 9. But you actually have a count of 10 if you are including the last number. So I was looking for a way to do a +1 in the function to equal 10.
I know that you have > and = operators that I use with ASP or I can do a +1, etc.
Like I said, not a big deal, but is there an easy way for just adding the +1 to make the count correct when counting the last number?
This code sets up event listeners for the two ID input fields that call the calculateCount() function whenever their values are changed. The function parses the input values as integers, adds them together, and updates the count input field with the result. If either input field contains a non-numeric value, the count input field will be left blank.
By using JavaScript, you can easily calculate and display the count of two IDs entered on a form, providing a double check to ensure the accuracy of the data entered.
would make the subtract function redundant.
Also disabling the Submit button would prevent the inadvertent form submission. Use a focus or change event listener on the count input to enable the button.