Click to See Complete Forum and Search --> : Weird stuff


xlegend
05-29-2003, 03:09 PM
Part one:

<html>
<head>
<script type="javascript">
function Choice(){

blah = document.form1.text1.value
var administration = "350"
var tuition = "300"
var rboard = "120"
var food = "150"
var one = ("300" * blah)
var two = ("120" * blah)
var three = ("150" * blah)
var four = one+two+three+administration

document.form1.text2.value==four
}
</script>
</head>
<body>
<form name='form1'>
<input type='text' name='text1' height='20' width='50'></textarea>
<input type='text' name='text2' height='20' width='50'></textarea>
<P><INPUT name=button2 onclick="Choice()" type=button value=Calculate>
</form>
</body>
</html>

I'm getting an object expected error on line 24 of this code. Could someone please tell me what that means?

Thank you

:D

Nevermore
05-29-2003, 03:17 PM
Just a few problems with your code:
Numbers don't need quotation marks around them. If you use quotes they can't be multiplied because they are strings.
You had set your script type to "javascript". Type needs to be text/javascript.

Here's the working script:

<script type="text/javascript" >
function Choice(){

blah = document.form1.text1.value
var administration = 350
var tuition = 300
var rboard = 120
var food = 150
var one = (300 * blah)
var two = (120 * blah)
var three = (150 * blah)
var four = one+two+three+administration

document.form1.text2.value=four;
}
</script>

xlegend
05-29-2003, 03:26 PM
I'm pretty sure I can handle part two now. :D

Charles
05-29-2003, 03:32 PM
Originally posted by cijori
Numbers don't need quotation marks around them. If you use quotes they can't be multiplied because they are strings. Then why does alert ('5' * '4') give you '20'?

JavaScript, being an untyped language, handles type conversion automatically. When you use a string primitive as a number it is first converted into its wrapper object String. Then String.valueOf() is called and the returned number primitive is used.