简体   繁体   中英

HTML-Javascript validation

Hey i want to check that there should not be any empty textboxes on submission. so i inserted a javascript on submit button but it does not work. All ID names are correct

function checkall()
{
    var a=window.document.getElementById("fname").value;
    var b=document.getElementById("lname").value;
    var c=document.getElementById("gender").value;
    var d=document.getElementById("dob").value;
    var e=document.getElementById("country").value;
    var f=document.getElementById("zip").value;
    var g=document.getElementById("email").value;
    var h=document.getElementById("pwd").value;
    if(a=="" || b=="" || c=="" || d=="" || e=="" || f=="" || g=="" || h=="" )
    {
        alert("bad");
        return false;
    }
    else
    {
        alert("good");
        return true;
    }
}

The submit button code is given below:

<input type="submit" value="Register" onClick="checkall()"/>

Help me out. Where i might have gone wrong ??

你需要在<form>标签中调用这个函数并让它返回函数的结果:

<form action="whatever" method="post" onSubmit="return checkall()">

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