/    Sign up×
Community /Pin to ProfileBookmark

Javascript eval not working

I’m making a javascript blackjack with betting. Currently, everything works except for the betting. When I win, the bet gets subtracted, which works. But when I win, For Example: I have $450 & I bet $50. when I win, my money goes to $45050. Why?

The script is as follows:
form.bets.value= eval((form.bets.value)+(form.betTotal.value));

I’ve tried this too:
form.bets.value= eval(form.bets.value)+(form.betTotal.value);

Neither work. Please help.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayAug 02.2009 — Try:

<i>
</i>form.bets.value= parseFloat(form.bets.value)+parseFloat(form.betTotal.value);
Copy linkTweet thisAlerts:
@justinbarneskinAug 02.2009 — form.bets.value= Number(form.bets.value)+Number(form.betTotal.value);
Copy linkTweet thisAlerts:
@mattwidgeauthorAug 02.2009 — Try:

<i>
</i>form.bets.value= parseFloat(form.bets.value)+parseFloat(form.betTotal.value);
[/QUOTE]


This works perfectly. Thanks!
×

Success!

Help @mattwidge 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.18,
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,
)...