简体   繁体   中英

Activate button only when form is all filled

I want to add a number rule to the Enter Admission Year section.

A number between 250-1000 must be entered.

The button should be disabled when the wrong number is added.

Can you help me with this? A value between 250-1000 must be entered

    <form role="form" id="contentHoldEdu" method="post">

<input id="Name" type="text" name="name" data-required="1" class="form-control"/>
<br>
<br>
<button class="btn btn-primary" id="Save" type="button">submit</button>
</form>

You need to create a variable status = false in your js.

on successfull validation of each element, keep updating this variable value and at the end of the loop, if it is still true, activate the btn else let it be deactivated.

hence if it is deactivated (which it is by default) nothing will happen on submit else, the submission will work just fine.

something like below should work for you though in ur script

var status = true;
function on()
{
    if(document.getElementById("miktar").value.length == 0){
        status &= true;
        }
    else{
        status = false;
    }

    if(document.getElementById("saat").value.length == 0){
        status &= true;
        }
    else{
        status = false;
    }
    if(document.getElementById("dakika").value.length == 0){
        status &= true;
        }
    else{
        status = false;
    }

    if(document.getElementById("kadi").value.length == 0){
        status &= true;
        }
    else{
        status = false;
    }

  document.getElementById("submit").disabled = status;
}

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