Click to See Complete Forum and Search --> : Using submit()


crvoss
07-03-2003, 05:24 PM
I can't seem to get this to work:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function stdCond() {
document.DensityInfo.DBTempUnits.options[0].selected = true;
}
// -->
</script>
<title>Page title</title>
</head>
<body>
<script language='javascript' type='text/javascript'>
function CheckEntry() {
document.DensityInfo.submit();
msg=document.DensityInfo.DBTemp.value + "\n" + document.DensityInfo.WBTemp.value
alert(msg);
location="Display.php";
}
</script>
<form method="post" action="FSStart.php" name="DensityInfo">
Drybulb Temperature:<input type="text" name="DBTemp" size="10" maxlength="15" value="">
Wetbulb Temperature:<input type="text" name="WBTemp" size="10" maxlength="15" value="">
<a class='btnbar' href="javascript:CheckEntry()">Next>></a>
</form>
</body>
</html>

-----------------------------
then I use this to examine the values:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Page title</title>
</head>
<body>
<?php
echo "Drybulb Temperature: $DBTemp";
echo "Wetbulb Temperature: $WBTemp";
?>
</body>
</html>

---------------------------------
The problem is that they are empty. If I place a submit button instead of a link in the first script everything works (but that is not what I am after). What am I doing wrong?

Charles
07-03-2003, 06:02 PM
1) Be careful that you do not make a page that will not work for the 13% of users that do not use JavaScript.

2) HTML 4.0 was done away with way back in 1999. Among other problems, it has no "name" attribute for the FORM element. Use HTML 4.01 Strict instead. (http://www.w3.org/TR/html4/)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
<form action="FSStart.php" name="densityInfo">
<div>
<label>Drybulb Temperature:<input type="text" name="DBTemp" size="10" maxlength="15" value=""></label>
<label>Wetbulb Temperature:<input type="text" name="WBTemp" size="10" maxlength="15" value=""></label>
<script type="text/javascript">
<!--
document.write('<a href="#">Next &amp;gt;</a>')
document.links[document.links.length-1].onclick = function () {document.forms.densityInfo.submit(); return false}
// -->
</script>
<noscript><button type="submit">Next &amp;gt;</button></noscript>
</div>
</form>