dscrn1974 2018-02-25 17:53
浏览 108

当我点击提交按钮时页面刷新的原因...文本框值变为空

<script type="text/javascript">
            

                // Fetching all HTML inputs

                var fullname=document.forms["myform"]["fullname"];
                var email=document.forms["myform"]["email"];
                var mobile=document.forms["myform"]["mobile"];
                var password=document.forms["myform"]["password"];
                var confirmpassword=document.forms["myform"]["confirmpassword"];

                //Fetching html component by their ID

                var fullname_error=document.getElementById("fullname_error");
                var email_error=document.getElementById("email_error");
                var mobile_error=document.getElementById("mobile_error");
                var password_error=document.getElementById("password_error");
                var confirmpassword_error=document.getElementById("confirmpassword_error");

                // Setting  event listner for  all inputs


                fullname.addEventListener("blur", nameVerify, true);
                email.addEventListener("blur()", emailVerify, true);
                mobile.addEventListener("blur()", mobileVerify, true);
                password.addEventListener("blur()", passwordVerify, true);
                confirmpassword.addEventListener("blur()", confirmpasswordVerify, true);





                function validate()
                {

                    if (fullname.value=="") 
                    {
                        fullname.style.borderColor = 'red';
                        fullname_error.textContent="Fullname is required";
                        fullname.focus();
                        return false;
                    }
                    else
                    {

                    }
                }           

                function nameVerify()
                {
                    if (fullname.value !="") {

                        fullname_error.innerHTML="";
                        return true;
                    }
                    else {
                        
                    }
                }   
        
</script>
.cssfullname
{
    color: red;
}
<!DOCTYPE html>
<html>
<head>
    <title>Registration</title>
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" type="text/css" href="index.css">
    

</head>
<body>
    
    

        <form role="form" method="post"  name="myform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
            <div>
                <input type="text" id="txt1" class="form-control" style="width: 200px;" name="fullname" placeholder="Fullname">
                <br>
                <div id="fullname_error" class="cssfullname"></div>
            </div>

            <div>
                <input type="text" id="txt2" class="form-control " style="width: 200px; name="email" placeholder="Email" >
                <br>
                <div id="email_error"></div>
            </div>

            <div>
                <input type="text" id="txt3" class="form-control" style="width: 200px; name="mobile" placeholder="Mobile">
                <br>
                <div id="mobile_error"></div>
            </div>

            <div>
                <input type="password" id="pass" class="form-control"  style="width: 200px;name="password" placeholder="Password">
                <br>
                <div id="password_error"></div>
            </div>

            <div>
                <input type="password" id="passcon" class="form-control" style="width: 200px; name="confirmpassword" placeholder="Confirm password">
                <br><br>
                <div id="confirmpassword_error"></div>
            </div>

            <div>
                <input type="submit" class="btn btn-success" onclick="validate()" name="btnsubmit" value="Submit">
                <br>
            </div>
        
        
        </form>
    

    
</body>
</html>
How to overcome that problem? what to do
when i click on submit....text becomes empty.........................................................

the error message also removed when click on submit button.the error message also removed when click on submit button.the error message also removed when click on submit button.the error message also removed when click on submit button.the error message also removed when click on submit button.the error message also removed when click on submit button.the error message also removed when click on submit button.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 易语言把MYSQL数据库中的数据添加至组合框
    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况