0
Good morning
How to take the value of equal inputs when clicking on the line.
function getValor(){
var valor = $('.produtos').val();
alert(valor)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input value="1" name="valor[]" class="produtos" type="button" onclick="getValor()">
<input value="2" name="valor[]" class="produtos" type="button" onclick="getValor()">
<input value="3" name="valor[]" class="produtos" type="button" onclick="getValor()">
<input value="4" name="valor[]" class="produtos" type="button" onclick="getValor()">
<input value="5" name="valor[]" class="produtos" type="button" onclick="getValor()">
Thank you very much Sergio
– frodrigues
@frodrigues I joined one more option
– Sergio
If the answer is correct don’t forget to mark with the right.
– David Mv
It was not cool to post not, but actually I want to get the value of an image by clicking on it. How would it be
– frodrigues
Hello @frodrigues, it seems to me that you are still struggling, I think you want to use jQuery within the function, if that’s the case, use the first example of @Sergio just you pass
input
to the selector from jQuery, getting like this$(input)
so you’ll be able to use$(input).val()
, I say this because you are trying to edit this answer to put the question code, if there is still any doubt comment on the answer or edit your question.– Icaro Martins
@frodrigues my answer answers your question. If your problem is another you should ask another question. You can’t ask a question with the problem
A
and expect me to respond with solution to the problemB
... if you want an image attribute you can use something like https://answall.com/q/197703/129– Sergio
ok. I’ll do another. Thanks for the help.
– frodrigues