View Full Version : I need help.
spiderseatbabie
06-01-2005, 10:24 PM
My friend wanted me to make a little javascript thing for him to see who he should sit next to on the bus (dont ask). And I cant get it to work.
I KNOW MOST, IF NOT ALL, OF IT IS WRONG.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function calc(){
if(n1<n2) then(document.write("let it sit"))
}
</script>
<title>Untitled</title>
</head>
<body>
<form>
IdiotFactor:<input type="text" name="n1">
IdiotFactor2:<input type="text" name="h2">
<input type="button" onClick="calc();" value="Check">
</form>
</body>
</html>
_Aerospace_Eng_
06-01-2005, 11:20 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function calc(){
if(document.forms['theform'].n1.value < document.forms['theform'].h2.value){
document.getElementById('solution').innerHTML="Let it sit.";
}
else if(document.forms['theform'].n1.value >= document.forms['theform'].h2.value){
document.getElementById('solution').innerHTML="Don't let it sit."
}
}
</script>
<title>Untitled</title>
</head>
<body>
<form name="theform">
IdiotFactor:<input type="text" name="n1">
IdiotFactor2:<input type="text" name="h2">
<input type="button" onClick="calc();" value="Check">
</form>
<span id="solution"></span>
</body>
</html>
spiderseatbabie
06-01-2005, 11:23 PM
Sweet thanks a bunch.
spiderseatbabie
06-01-2005, 11:37 PM
Do you know how to add another input, that would add it's number to the second input's number?
_Aerospace_Eng_
06-04-2005, 06:07 PM
so would you be checking to see if the two numbers added together are greater than the first input, let them sit, if not don't let them sit?
spiderseatbabie
06-04-2005, 06:16 PM
Kinda like that, but lets say that if the 2+3=>1 they sit, if 2+3=<1 then they sit...
_Aerospace_Eng_
06-04-2005, 06:19 PM
So basically not equal to the first input?
_Aerospace_Eng_
06-04-2005, 06:39 PM
I have now made it to where it uses the submit button so you can press enter to get the value instead of having to hit the Check button each time. If factor2+factor3 are equal to factor1 it will display 'Don't let it sit.' If factor2+factor3 is anything but factor1 it will display 'Let it sit.'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function calc(){
var factor1=Number(document.forms['theform'].n1.value);
var factor2=Number(document.forms['theform'].h2.value);
var factor3=Number(document.forms['theform'].h3.value);
var factor2_3=factor2+factor3;
if(factor1 < factor2_3 || factor1 > factor2_3){
document.getElementById('solution').innerHTML="Let it sit.";
}
else if(factor1 == factor2_3){
document.getElementById('solution').innerHTML="Don't let it sit."
}
return false;
}
</script>
<title>Untitled</title>
</head>
<body>
<form name="theform" action="" method="post" onsubmit="return calc();">
Factor1:<input type="text" name="n1">
Factor2:<input type="text" name="h2">
Factor3:<input type="text" name="h3">
<input type="submit" value="Check">
</form>
<span id="solution"></span>
</body>
</html>
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.