0

This is my code:

$(document).ready(function() {

$( "#kartyaazonosito" ).on( "focusout", function() {
console.log( $( this ).val() ); // I need the actual input value (from the actual line)
});

$( "#biztonsagikod" ).on( "focusout", function() {
console.log( $( this ).val() );// I need the actual input value (from the actual line)
});

});

1."line":

<input placeholder=" " class="o-input__field" type="text" name="cards[0].code" id="biztonsagikod" />

2."line":


<input placeholder=" " class="o-input__field" type="text" name="cards[1].code" id="biztonsagikod" />

The users can be add more and more "lines". The on focusout works only for the 1. "line". How can I solve that, the focusout works the 2."line", and 3. line, etc..

3
  • 4
    IDs have to be unique per document, you should use a class instead Commented Oct 21, 2020 at 9:40
  • <input class="o-input__field biztonsagikod"... then $(".biztonsagikod").on(... - also assumes they aren't added after your jquery runs (which doesn't appear to be the case as it "works for line 1") Commented Oct 21, 2020 at 9:43
  • Thanks! It's working with your solution :) Commented Oct 21, 2020 at 10:11

1 Answer 1

1

You can declare a common function and put it as onfocusout event instead.

function myFunction(x) {   
     console.log( x.value );
}
<input placeholder=" " class="o-input__field" type="text" name="cards[0].code" onfocusout="myFunction(this)" />
<input placeholder=" " class="o-input__field" type="text" name="cards[1].code" onfocusout="myFunction(this)" />

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It's great! :)

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.