0

I have an input where I want to show an icon X if the length is < 1. If the lenght is bigger than 1 i want to print a tick icon:

For that I want to use the functions change, keyup, and focusout.

This functins it doesn't work because I don't know how to identify the input correctly. I can't use the input's id because that id is DYNAMIC.

I have tried using that:

$( "filaa-enq" ).change(function()

$( "filaa-enq" ).keyup(function()

$( "filaa-enq" ).focusout(function()

enter image description here

<div class="input">
  <label class="text-mida">
     <div class="fila-enq"><input class="filaa-enq" type="input" name="question_1_1_0" value="" maxlength="20" id="question_1_1_0"><span style="display:none" class="validate_ok_enquesta fa fa-check"></span><span style="display:none" class="validate_ko_enquesta fa fa-times"></span></div>
  </label>
</div>
$( ".filaa-enq" ).keyup(function() {
        console.log("ttttt");
        checkEnquesta(this); 
 });

$( "filaa-enq" ).focusout(function() {
        console.log("test");
        checkEnquesta(this); 
  });

$( "filaa-enq" ).change(function() {
        console.log("changees");
        checkEnquesta(this); 
});

function checkEnquesta(element){
    console.log(element);
    if (element.value=="") {
        $('#'+element.id).siblings(".validate_ko_enquesta").hide();
        $('#'+element.id).siblings(".validate_ok_enquesta").hide();
        return false;
    }
    if (element.value.length > 1 ){
        $('#'+element.id).siblings(".validate_ok_enquesta").show();
        $('#'+element.id).siblings(".validate_ko_enquesta").hide();
    }
    else{
        $('#'+element.id).siblings(".validate_ko_enquesta").show();
        $('#'+element.id).siblings(".validate_ok_enquesta").hide();
    }
}
.validate_ok_enquesta{
    float: right;
    margin-right: 6px;
    margin-top: -35px;
    position: relative;
    z-index: 2;
    color:green;
}

.validate_ko_enquesta{
    float: right;
    margin-right: 6px;
    margin-top: -35px;
    position: relative;
    z-index: 2;
    color:red;
}

How I can pass the id? If that id is dynamic?

proera
  • 115
  • 8

0 Answers0