Forum Moderators: open
Best regards
Michal Cibor
The code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function java_change()
{
var a = document.a;
if(a.b.value == "")
{
alert("Please fill in the input b");
a.b.select();
}
else
{
if(a.b.value!= a.c.value)
{
alert("Input b and c must be the same.")
a.c.select();
}
else
{
if(confirm("Are you sure?"))
{
a.submit();
}
}
}
}
//-->
</script>
</head>
<body>
<form name="a" action="l.html" method="post">
<input type="text" name="b"><input type="text" name="c">
<button onclick="java_change()">Change</button></form>
</body>
</html>
The fixes are here:
1) give your elements an id alongside their name. The id and name can be the same.
2) use the w3c document.getElementById() to reference the elements instead of the flat IE DOM model.