I'm a totally beginner in javascript. i need some chunks of code of it.
i have a form. i'm going to store the field into mysql. there are 2 conditions : one or all fields empty OR none is empty.
when there's no empty field, the data will be stored. but, when there's empty field, no data will be stored and there will come up the alert "please fill all the fields!"
here's the form :
<form method=POST enctype='multipart/form-data' onclick='show_alert()' action=insert.php>
<table>
<tr><td>Data 1</td> <td><input type=text name='data1'> </td></tr>
<tr><td>Data 2</td> <td><input type=text name='data2'> </td></tr>
<tr><td>Data 3</td> <td><input type=text name='data3'> </td></tr>
<tr><td colspan='2'><input type=submit value='Save'><input type=button value=Cancel onclick=self.history.back()></td></tr>
</table></form>";
here's the insert script:
if(!empty($_POST['data1'])&& !empty($_POST['data2'])&& !empty($_POST['data3'])){
mysql_query("INSERT INTO tabel_data(dataA,dataB,dataC)
VALUES('$_POST[data1]','$_POST[data2]','$_POST[data3]')") or die(mysql_error());
header('location:form.php');}
else{?>
<script type="text/javascript">
function show_alert()
{
alert("Please fill all fields!");
}
</script>
<?php header('location:form.php');
}
i don't know how to show the alert with javasript. Please help me with the code..thank you.