/    Sign up×
Community /Pin to ProfileBookmark

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

?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreMay 29.2003 — 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:

[CODE]<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>[/CODE]
Copy linkTweet thisAlerts:
@xlegendauthorMay 29.2003 — I'm pretty sure I can handle part two now. ?
Copy linkTweet thisAlerts:
@CharlesMay 29.2003 — [i]Originally posted by cijori [/i]

[B]Numbers don't need quotation marks around them. If you use quotes they can't be multiplied because they are strings. [/B][/QUOTE]
[font=georgia]Then why does [font=monospace]alert ('5' * '4')[/font] 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.[/font]
×

Success!

Help @xlegend spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...