BVP
BVP

Reputation: 21

How to alert a value in jQuery using if condition

I have an if condition in jQuery,

if (($("input[value=Add]").prop("disabled") == true) || ($("input[value=Modify]").prop("disabled") == true) || ($("input[value=Delete]").prop("disabled") == true))

I need to alert the value which will show me true or false depending on the above if condition. Can someone help me with the alert statement?

Upvotes: 0

Views: 1498

Answers (2)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196002

I am assuming you want the value of the first input element that was disabled.

var inputs = [ $("input[value=Add]")[0], 
               $("input[value=Modify]")[0], 
               $("input[value=Delete]")[0] ], // put the relevant input (raw DOM element) in an array
    disabled = inputs.filter(input => input.disabled); // filter the disabled ones only

if (disabled.length) alert(disabled[0].value); // if a disabled exist alert the first ones value

If, on the other hand, only one can be disabled then you can do it directly

var disabled = $("input[value=Add],input[value=Modify],input[value=Delete]").filter(':disabled');

if (disabled.length) alert(disabled.val());

Upvotes: 1

MNI Noyon
MNI Noyon

Reputation: 98

Simply try to use Javascripts alert() function after the if condition

if (($("input[value=Add]").prop("disabled") == true) ||
($("input[value=Modify]").prop("disabled") == true) || ($("input[value=Delete]").prop("disabled") == true)){
alert("Your alert text");
}

Upvotes: 0

Related Questions