0

I nee d get mutiple value from a lookup field and i need to validate it,if i get more than one value i need to give a message and if get one value i need to give another message.i have try something but it not work.

function getbankdetails()
{     
  debugger;
  var arr = $('#R3413775').val();
  
  if(arr[0]!="" && arr[1] !="")
  {
    alert("first"+arr[0]+" "+arr[1]);
  }
  else
  { 
    alert("sasa");
  }  
  
}

4
  • why are you cheching arr[0] 2 times in if condition Commented Oct 25, 2018 at 4:07
  • actually it is mistake but it is not real problem,i change it and check again it not work if i use arr[0] and arr[1] Commented Oct 25, 2018 at 4:10
  • can u share your output? I have given an answer if you share your exact output and expected output it will be clear Commented Oct 25, 2018 at 4:15
  • @saketh according to the above code when i select one value alert show " first value undefined" if i select two values alert show in twice first time show " first value undefine" and second time show "first value value" Commented Oct 25, 2018 at 4:23

2 Answers 2

1

This may work (Javascript)

function getbankdetails()
{     
  debugger;
  var arr = Array.from(document.getElementById("R3413775").selectedOptions).map((ele) => ele.value)      
  if(arr[0] && arr[1] && arr.length == 2)
  {
     alert("first"+arr[0]+" "+arr[1]);
  }
  else
  { 
     alert("sasa");
  }      
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can simply get the elements as the array and either console log the "sasa" string or the list of selected items as a string (by concatenating the array with commas.

$('#R3413775').change(function(){
  getbankdetails();
})

function getbankdetails() {     
  var arr = $('#R3413775').val();
  arr.length == 1 
   ? console.log("sasa")
   : console.log(arr.join(', '))
} 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="R3413775" multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel" >Opel</option>
  <option value="audi">Audi</option>
</select>

Comments

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.