简体   繁体   中英

How can I disable a form with javascript onchange function?

I'm trying to disable a form in a JSP just when two conditions become true. I've tried a var variable set false so when my if-else condition becomes true it becomes true. But it is not working.

Here is my code. (not sure if it can help but I'm using eclipse)

var disabled=false;

then I've created the function

function isDisable(){
    if($("#idCost").val() == 1 && $("#IdBasket").val() == "3"){
        disabled=true;
    }
}

and then set in the form field

< disabled="false"/>

What am I doing wrong?

Thanks for helping

It looks like your code is in JavaScript and not Java, even though you say you are writing a JSP.

Your JS code compare one return to a Number (val() == 1) and another to a String val() == "3". Did you try making them both the same? If .val() is returning strings, then they should both compare to strings. If .val() is returning numbers, then they should both compare to numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM