0

I want to remove an input id when another input id having value in defined values

my codes

setInterval(function() {
  var MaterialGod = [
    "FPPUTHP1100000",
    "FPPUTHP1100000",
    "FPPUTHP1110000",
    "FPPUTHP1500000",
    "FPPUTHP1680000",
    "FPPUTHP1690000",
    "FPPUTHP1590000"
  ];

  $.each(MaterialGod, function(index) {
    if ($("label:contains('Meterial Code')").parent().next().find('input').val() == index) {
      $('#__item5-__box2-0').remove();
    }
  })
}, 100);

Pls give your advise what i m doing wrong

3
  • index is the array index, not the value of the array element. Commented May 28, 2020 at 18:51
  • The second argument to the callback function is the element. Commented May 28, 2020 at 18:51
  • @Barmar Dear Sir i am a newbie pls correct my codes Commented May 28, 2020 at 18:54

2 Answers 2

2

If am not wrong you are comparing with index instead of value. Try comparing with value as shown in below code.

  setInterval(function() {
      var MaterialGod = [
        "FPPUTHP1100000",
        "FPPUTHP1100000",
        "FPPUTHP1110000",
        "FPPUTHP1500000",
        "FPPUTHP1680000",
        "FPPUTHP1690000",
        "FPPUTHP1590000"
      ];
    
      $.each(MaterialGod, function(index,iVal) {
        if ($("label:contains('Meterial Code')").parent().next().find('input').val() == iVal) {
          $('#__item5-__box2-0').remove();
        }
      })
    }, 100);
Sign up to request clarification or add additional context in comments.

Comments

1

You're comparing the array index, not the array element, with the value.

There's also no reason to put the selector in the loop, since you're selecting the same input every time.

Just get the input value, and use .includes() to see if it's in the array.

setInterval(function() {
  var MaterialGod = [
    "FPPUTHP1100000",
    "FPPUTHP1100000",
    "FPPUTHP1110000",
    "FPPUTHP1500000",
    "FPPUTHP1680000",
    "FPPUTHP1690000",
    "FPPUTHP1590000"
  ];
  if MaterialGod.includes($("label:contains('Meterial Code')").parent().next().find('input').val()) {
    $('#__item5-__box2-0').remove();
  }
}, 100);

10 Comments

Its Worked Fine... Thanks :) I am a new user so cant vote UP
@SachinAgarwal You've changed the question completely. If you have a different problem, post a new question.
@Barmar I m a new user stackoverflow banned me for asking new question....it was very urgent
$(this).find("option:selected").text() contains the text of the selected option. You can show that in the other place.
@Barmar its not working.. may be i am doing something wrong.. can you post the whole code here?
|

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.