I'm trying to implement the DRY principle in my programming style.
To prevent misunderstanding about my question above, I will explain it one more time below. I did searching for this solution all the time, but it seems I can't find the right solution.
I want to get each input value in the form dynamically (not a dynamic inputs, add new input dynamically, etc.) without going to type this over and over:
var foo = $('input[name="foo"]').val();
var bar = $('input[name="bar"]').val();
For one or two pieces, it will be all right. But the problem is when I have more than 10 inputs, it's going to be unacceptable.
How can I do this?
const getInputByName = (name) => $(`input[name=${name}]`), and call it by doingvar $foo = getInputByName("foo");. I'd submit this as an answer if your desired result was a bit more clear to me.fooinput, eventually you're gonna have to specifyfoo. If you're just trying to get all inputs, or all empty inputs, or all filled inputs, or all text inputs, etc, then this is easier. But your question doesn't make sense. We need to know what you plan on doing with the inputs.