/    Sign up×
Community /Pin to ProfileBookmark

Flaw in Code?

i was wondering why nothing is showing up on this piece of code…

im sure ive covered everything.

any help is much appreciated?

[CODE]function calculate(form1)
{
var price = 52.0 ;

if (form1.membership.value ==”1″)
price *= .25 ;

else if (form1.membership.value ==”2″)
price /= .50 ;

else if (form1.membership.value ==”3″)
price /= .75 ;

else if (form1.membership.value ==”4″)
price *= 1 ;

if (form1.duration[0].checked)
price += 2 ;

else if (form1.duration[1].checked)
price *= 1 ;

form1.cost.value=price ;
}[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorJun 04.2008 — And the function is called by [I]which event[/I], from [I]where[/I]? Can we see the HTML part, as well?
Copy linkTweet thisAlerts:
@JMRKERJun 04.2008 — While this doesn't change @Kor's comment, it does simplify the code somewhat ...
[code=php]
function calculate(form1) {
var price = 52.0 ;
var member = form1.membership.value;
switch (member) {
case '1': price *= 0.25; break;
case '2': price /= 0.50; break;
case '3': price /= 0.75; break;
default: price *= 1; break;
}
if (form1.duration[0].checked) { price += 2; }
if (form1.duration[1].checked) { price *= 1; }
form1.cost.value=price ;
}
[/code]
Copy linkTweet thisAlerts:
@Declan1991Jun 04.2008 — Or even more:[code=php]
function calculate(form1) {
var price = 52.0;
switch (form1.membership.value) {
case '1': price *= 0.25; break;
case '2': price *= 2; break;
case '3': price /= 0.75; break;

}
if (form1.duration[0].checked) { price += 2; }
form1.cost.value=price ;
}
[/code]
Copy linkTweet thisAlerts:
@sirproauthorJun 04.2008 — while its just homework for tafe, ive taken an extreme interest in this area of the internet and computers.

here is the html code
[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>best hats club</title>
<script language="javascript" type="text/javascript" src="homework.js"></script>
</head>
<body>
<h1 style="text-align:center">Best Hats</h1>
<form action="javascript:calculate(form1)" name="form1">
Membership Number:<input type="text" name="membernumber">
<br/><br/>
Member Name:<input type="text" name="membername">
<br/><br/>
Duration:
<input name="duration" type="radio" value="12months"/> 1 year
<input name="duration" type="radio" value="6months"/> 6 months
<br/><br/>
Membership Type:
<select name="membership">
<option value="1">Junior</option>
<option value="2">Begginner</option>
<option value="3">Intermediate</option>
<option value="4">Advanced</option>
</select>
<p><p/>
<p><p/>
Cost:
<input type="text" name="cost" disabled>
<p><p/>
<input type="submit" value="purchase"/>
</form>
</body>
</html>[/CODE]


as for the two 'simplified' examples...do they still work if i save the document as .js (obviously not, worth asking anyway)?
×

Success!

Help @sirpro 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.28,
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,
)...