user3740978
user3740978

Reputation: 7

Javascript Alert is not working with echo

if (isset($_POST['tambah'])) {
    $id_wilayah = $_POST['id_wilayah'];
    $nama_wilayah = $_POST['nama_wilayah'];
    $_wilayah = "INSERT INTO wilayah_desa VALUES (?, ?, '')";
    $stmt = mysqli_prepare($link,$_wilayah);
    mysqli_stmt_bind_param($stmt, 'ss', $id_wilayah, $nama_wilayah);
    mysqli_stmt_execute($stmt);
    echo "<script language=\"JavaScript\">alert('Data Wilayah Desa Berhasil       Disimpan!');</script>";
    header('location:wilayah.php');

the Javascript alert is not working. is there anything wrong? I appreciate all answer. thank you

Upvotes: 0

Views: 402

Answers (3)

Kylie
Kylie

Reputation: 11759

Try this...

echo "<script>alert('Data Wilayah Desa Berhasil       Disimpan!');</script>";

But its likely not working because the header is redirecting you before the script fires

Upvotes: 0

Obadah Hammoud
Obadah Hammoud

Reputation: 572

The problem is not with Javascript; It's because that you added: header('location:wilayah.php'); it will instantly go there without even trying to apply the script removed it and worked for me ^_^

Upvotes: 4

Bluefire
Bluefire

Reputation: 14139

It should be type="text/javascript, instead of language="Javascript. Heck, if I recall correctly, you don't even need this. Try:

echo "<script>alert('Data Wilayah Desa Berhasil       Disimpan!');</script>";

Upvotes: 0

Related Questions