PDA

View Full Version : Please Help! parseInt and evil form resetting...


hdub
11-27-2007, 10:40 PM
I was assigned a pretty simple javascript problem for an intro to csc class...and it just refuses to work! I've checked it in firebug, and there are NO errors...but when I click submit the from simply resets and fails to execute. Please, please help me.


<html>
<head>
<script language=Javascript>
function display()
{

var today = new Date();
var hours = today.getHours();
var helloMessage ="";
var name = "";

name = document.myform.name.value;

var cMonth = today.getMonth();
var day = today.getDate();
var year = today.getFullYear();




if (hours <12)
helloMessage = "Good Morning";
else if (hours >5)
helloMessage="Good Afternoon";
else if (hours <5)
helloMessage= "Good Evening";


var biM ="";
biM= document.input.myform.bmonth.value;
biM= parseInt(x);

var bY="";
bY= document.input.myform.biyear.value;
bY= parseInt(l);



l=cMonth-biM;
x= year-bY;
if (month < biM);
else l=12-(cMonth-biM);




document.write("<body>");
document.write( "It is " + month + "/" + day + "/" + year)
document.write("<br> <br>");
document.write(helloMessage + "+name+");
document.write( "You will be" +x+ "years in" +l+ "months");
document.write ("</body>");
document.write ("</html>");
document.close();
}
</script>
</head>
<body>
<form name="myform">
Name:
<input type="text" name="name" value="">
<br>
<br>
Birth Month (1-12):
<input type="text" name="bmonth" size="2" value="">
<br>
<br>
Birth Date (1-31):
<input type="text" name="bdate" size="2" value="">
<br>
<br>
Birth Year (19XX)
<input type="text" name="biyear" size="5" value="">
<br><br>
<input type="Submit" onclick ="display()" value="Submit">
</form>




</body>
</html>


thank you

Trinithis
11-27-2007, 11:13 PM
*Misread. Rereading and will give new advise in a minute. Wish there was a Delete button...

Trinithis
11-27-2007, 11:36 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<title>Test</title>
<head>
<script type="text/javascript">

function display() {
var today = new Date();
var hours = today.getHours();
var helloMessage = "";
var name = document.myform.name.value;
var month = today.getMonth();
var day = today.getDate();
var year = today.getFullYear();
if(hours < 12)
helloMessage = "Good Morning";
else if(hours > 5)
helloMessage = "Good Afternoon";
else
helloMessage = "Good Evening";
var biM = document.forms.myform.bmonth.value;
var bY = document.forms.myform.biyear.value;
var l = (month - biM) - 0;
var x = (year - bY) - 0;
if(month >= biM)
l = 12 - month + biM;
document.write( "It is " + month + "/" + day + "/" + year)
document.write("<br \/>");
document.write(helloMessage + " " + name);
document.write("<br \/>");
document.write( "You will be " + x + " years in " + l + " months");
document.close();
}
</script>

</head>


<body>
<form name="myform">
Name:
<input type="text" name="name" value="" />
<br />
<br />
Birth Month (1-12):
<input type="text" name="bmonth" size="2" value="" />
<br />
<br />
Birth Date (1-31):
<input type="text" name="bdate" size="2" value="" />
<br />
<br />
Birth Year (19XX)
<input type="text" name="biyear" size="5" value="" />
<br />
<br />
<input type="button" onclick="display()" value="Submit" />
</form>




</body>
</html>

hdub
11-27-2007, 11:45 PM
Thank you...so, so much.

Trinithis
11-27-2007, 11:49 PM
Tip: If you look at your old code in a FF, the errors will show in its error console after you click the button.