mardi 31 mars 2020

Efficient way to use If statement for checking the value is not being used in Javascript or JQuery

I have four textboxes say textbox1, textbox2, textbox3, textbox4 in my HTML doc on a button click for btn1 I want to make sure that all the values entered in all four textboxes are distinct & unique. For which I am using the if condition.

$("#btn1").on("click", function(){

    if($("#textbox1").val() === $("#textbox2").val() || 
       $("#textbox1").val() === $("#textbox3").val() ||
       $("#textbox1").val() === $("#textbox4").val() ||
       $("#textbox2").val() === $("#textbox3").val() || 
       $("#textbox2").val() === $("#textbox4").val() ||
       $("#textbox3").val() === $("#textbox4").val() ) 
    {  alert("Values are not unique please check them."); }

});

Is there any way shorter than this?

Aucun commentaire:

Enregistrer un commentaire