/    Sign up×
Community /Pin to ProfileBookmark

Quick Image Calculation

I have a bit of code here that I created, and I was hoping someone could tell me where my error is. The goal is to click an image whose value is “x” and the text area value becomes itself + x. The end goal is to have 5 images with 5 different values, and clicking one adds a different amount to the textarea… Here is the code:

<form name=RupCalculate>

<script language=”JavaScript”><!–
function RupCalculate()
{
eval(“document.RupCalculate.RupTotal.value = ”;”);
eval(“q = document.RupCalculate.GreenRup.value;”);
if (q)
{
eval(“document.RupCalculate.RupCalculate.value=’1′”);
}
}
// –></script>

<img src=images/GreenRup.bmp name=GreenRup onclick=”RupCalculate();” Value=1><br><br>

<input type=text name=RupTotal value=0 onfocus=”this.blur();”><br><br>

</form>

I have also tried input type=image. But that creates a submit type button and changes the page back to itself with a querystring. I want it all to stay on one page, if ya know what I mean. Thanks for any help.

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@SuamereauthorJun 26.2005 — I have a better idea, more simplified, yet still not working. Look at this... When I click the buttons "5" and "10" The output becomes "510" and then if I press "5" again, the output becomes "5105" etc... So it is combining strings instead of adding values. Could this be fixed:?



<form name=RupCalculate>

<INPUT TYPE="button" NAME="Rup5" VALUE="5" OnClick="RupCalculate.RupTotal.value = eval(RupCalculate.RupTotal.value + 5)">

<INPUT TYPE="button" NAME="Rup10" VALUE="10" OnClick="RupCalculate.RupTotal.value = eval(RupCalculate.RupTotal.value + 10)">

<INPUT TYPE="button" NAME="Rup20" VALUE="20" OnClick="RupCalculate.RupTotal.value = eval(RupCalculate.RupTotal.value + 20)">

<br><br>

<input type=text name=RupTotal><br><br>

</form>
Copy linkTweet thisAlerts:
@HaganeNoKokoroJun 26.2005 — Since [font=courier]RupCalculate.RupTotal.value[/font] is a string, it is concatenating instead of adding numerically. Try&lt;INPUT TYPE="button" NAME="Rup5" VALUE="5" OnClick="RupCalculate.RupTotal.value = [color=red]parseInt([/color]RupCalculate.RupTotal.value[color=red])[/color]+5"&gt;
Copy linkTweet thisAlerts:
@SuamereauthorJun 26.2005 — Thank you. That works perfectly. I tried ParseInt before, but it was within the eval, which is probably why it didn't work. Have a good day!
×

Success!

Help @Suamere 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.16,
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,
)...