I’m new to web design/development; I have the following code to check if data is entered inside the text boxes. The JavaScript checks if data is added and comes up with a error if not entered?
This script works on FireFox but not on Google Chrome. The error messages don’t appear and the data is added straight to the database.
<script type="text/javascript">
function validate(){
if(
document.vulcanoForm.device_name.value == "" ||
document.vulcanoForm.muid.value == "" ||
document.vulcanoForm.map_version.value == "0.000")
{
alert("Please fill out all fields before clicking submit!");
return false;
}
else
{
alert("Hold on just adding to database :)");
return true;
}
}
</script>
<body>
<a href="index.xhtml"> Mogadishu </a> <br/>
<form action="vulcanoprocess.php" method="post" onsubmit="return validate()" name="vulcanoForm">
<fieldset>
<legend>Device Information</legend>
<label for="device_name">Device Name:</label><br />
<input type="text" name="device_name" id="device_name" /><br />
<label for="muid">MUID:</label><br />
<input type="text" name="muid" id="muid" /><br />
</form>
</body>
To debug, use FireBug as a Firefox add on and select the javascript tab for errors or ‘console’. Use that information to fix errors in code and when they go away test the script in chrome. If there are still errors, it might be because the chrome browser is missing some type of compatibility with js.