/    Sign up×
Community /Pin to ProfileBookmark

Stats inc/decrement table

Hi
I need a table like below
[URL=”http://img25.imageshack.us/img25/9568/screenshotkoc.jpg”]http://img25.imageshack.us/img25/9568/screenshotkoc.jpg[/URL]

I am new to javascript and have several ideas after going on the w3c website but can’t seem to glue the ideas together. Any help appreciated.

I have a pool of stats point (say 20) that can be assigned to various attributes which have starting values (say 8) . I want a text box for the starting value and images for plus or minus to decrement or increment the stats whilst modifying the pool of overall stats points.

So far my ideas are to use onmouseclick and
I have written
if $a ($tb ++ && $p — while $p>0);
if $b ($tb — && $p ++ while $p<20);

I have the idea to define the plus image as $a, minus image $b the pool of stats $p and the text box with starting value (which I have to find out how to set) as $tb.

I have no clue if this will work or if I’ve got muddled with php and am struggling to glue it together with the form inputs and onmouseclick.

My form is as follows (class=”tb” is from the css file and applies style to the textboxes):

[CODE]<div id=”stats” >

<font color=”#6B50C1″ face=”achafont” size=”2″>
<table class=”statstable” border=”0″ cellpadding=”10″>
<tr ><td>Deftness</td><td><img src=”images/minus.jpg” alt=”minus”
/><input type=”textbox” name=”deftness” size=”1″ class=”tb”/><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr ><td>Charm</td><td><img src=”images/minus.jpg” alt=”minus” /><input type=”textbox” size=”1″ name=”charm” class=”tb” /><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr ><td>Wit</td><td><img src=”images/minus.jpg” alt=”minus” /><input type=”textbox” name=”wit” size=”1″ class=”tb” /><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr ><td>Magika</td><td><img src=”images/minus.jpg” alt=”minus” /><input type=”textbox” size=”1″ name=”magika” class=”tb” /><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr ><td>Clarity</td><td><img src=”images/minus.jpg” alt=”minus” /><input type=”textbox” name=”clarity” size=”1″ class=”tb” /><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr ><td>Ruthlessness &nbsp;</td><td><img src=”images/minus.jpg” alt=”minus” /><input type=”textbox” size=”1″ name=”ruthlessness” class=”tb” /><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr ><td>Stealthiness </td><td><img src=”images/minus.jpg” alt=”minus” /><input type=”textbox” size=”1″ name=”stealthiness” class=”tb” /><img src=”images/plus.jpg” alt=”plus” /></td></tr>
<tr><td colspan=”2″>Points to spend=xx</td></tr>
</table><br /><br />
</font>

</div>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@omnicityNov 03.2009 — onclick should work fine for this, (it is NOT onMOUSEclick), though some people might try and encourage you to use event capture instead.

The big advantage if you do use onclick is that you can then almost certainly keep all of the code within the onclick; something like:

[CODE]onclick="if(thisForm.charm.value < 20){thisForm.charm.value++;}"
[/CODE]
(for the plus buttons)

and
[CODE]onclick="if(thisForm.charm.value > 0){thisForm.charm.value--;}"
[/CODE]
(for the minus buttons)

Assuming that these elements are part of a <FORM> called: thisForm
×

Success!

Help @catelee2u 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...