使用javascript(未知错误)验证HTML表单,然后将其指向php文件

时间:2022-10-16 10:53:33

I'm helping on making a mobile application. I helped by looking up to the similar script on the program. There are form for registration and the javascript for validation works fine in it, but when I tried to make the password change form, it doesn't work all.

我正在帮助制作移动应用程序。我通过查阅程序中的类似脚本来帮助我。有注册表单和验证的javascript工作正常,但当我尝试进行密码更改表单时,它不起作用。

Here's the html form in pengaturan.html

这是pengaturan.html中的html表单

<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="css/style1.css" />

<script src="jq/proses/script.js"></script>
<script src="jq/proses/set_ip.js"></script>
<script src="jq/proses/newpass/newpass.js"></script>

<title>edc - e diabet consult</title>
</head>
<body>
<h1 align="center">Pengaturan</h1>

<p align="left" class="navigation">

<a href="settings.html" class="back">
<img src="ico/kembali.png">
</a>

</p>

<form id="form_pengaturan">

<p align="center">

<strong>Password lama:</strong><br />
<input type="password" name="pass" /><br />

<strong>Password baru:</strong><br />
<input type="password" name="newpass" /><br />

<strong>Konfirmasi password baru:</strong><br />
<input type="password" name="confnewpass" /><br /><br/>

<input type="button" value="Simpan" onclick="cek_pass()" id="simpan" class="button"></button> 
<input type="reset" value="Reset" class="button"/>

</p>
</form>
</body>
</html>

Here's the javascript to handle the onclick function in newpass.js

这是在newpass.js中处理onclick函数的javascript

var urlini = seturl();
var part= 'newpass/';
//alert("panggil newlog js!");

//Save data into db
function cek_pass() {
    //alert("masuk func cek!"); 
    pass =  ($("#pass").val()); 
    newpass =  /^([-a-z0-9_-])+$/i.test($("#newpass").val());
    confnewpass =  /^([-a-z0-9_-])+$/i.test($("#confnewpass").val());

    var form_reg =  $("input").val();
    if(form_reg == "")
    {
        alert("Semua data harus diisi.");
    }
    else if($("#newpass, #confnewpass").val().length  < 5 || $("#newpass, #confnewpass").val().length > 15)
    {
        alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda lebih dari 5 dan kurang dari 15 karakter.");
    }
    else if( !pass || !newpass || !confnewpass || $("#newpass").val() != $("#confnewpass").val())
    {
        alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda sesuai.");
    }
    else
    {
        $.post(urlini+part+'cek',
        $('#form_pengaturan').serialize(),function(msg){
        if(msg == '0')
        {
            alert("Password yang anda masukkan tidak benar!");
        }
        else if(msg == '1')
        {
            alert("Data berhasil disimpan!");
            window.location="index.html";
        }
    });
    }

}

Here's the javascript to handle the change address to the server in set_ip.js

这是用于处理set_ip.js中服务器的更改地址的javascript

//where the set the domain name
var ip = 'localhost';
var urlnya = 'http://'+ip+'/diabet_console/';
function seturl()
{    
    return urlnya;
}

Could you tell me where I wrong? because the javascript : newpass.js doesn't work as it suppose to be... Please help me.... Thanks

你能告诉我哪里错了吗?因为javascript:newpass.js不起作用,因为它假设是...请帮助我....谢谢

1 个解决方案

#1


0  

Add return false

添加返回false

if(form_reg == "")
    {
        alert("Semua data harus diisi.");
        return false   
    }
    else if($("#newpass, #confnewpass").val().length  < 5 || $("#newpass, #confnewpass").val().length > 15)
    {
        alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda lebih dari 5 dan kurang dari 15 karakter.");
       return false;
    }
    else if( !pass || !newpass || !confnewpass || $("#newpass").val() != $("#confnewpass").val())
    {
        alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda sesuai.");
        return false;
    }

#1


0  

Add return false

添加返回false

if(form_reg == "")
    {
        alert("Semua data harus diisi.");
        return false   
    }
    else if($("#newpass, #confnewpass").val().length  < 5 || $("#newpass, #confnewpass").val().length > 15)
    {
        alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda lebih dari 5 dan kurang dari 15 karakter.");
       return false;
    }
    else if( !pass || !newpass || !confnewpass || $("#newpass").val() != $("#confnewpass").val())
    {
        alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda sesuai.");
        return false;
    }