It looks like you're new here. If you want to get involved, click one of these buttons!
Points left to spend:
<<set $Sklpoints = 20>><<id "stats-$Sklpoints">><<print $Sklpoints>><</id>>
<br>
<br>
<p id="p1">
<center>Strength:
<<set $pcStr = 10>><<id "stats-str">><<print $pcStr>><</id>>
<br>
<<click "[+]">><<set $pcStr++>><<set $Sklpoints++>><<replace "#stats-str">><<print $pcStr>><</replace>><<replace "#stats-$Sklpoints">><<print $Sklpoints>><</replace>><</click>> |
<<click "[-]">><<set $pcStr-->><<set $Sklpoints-->><<replace "#stats-str">><<print $pcStr>><</replace>><<replace "#stats-$Sklpoints">><<print $Sklpoints>><</replace>><</click>></center>
</p>
<p id="p1">
<center>Agility:
<<set $pcAgl = 10>><<id "stats-agl">><<print $pcAgl>><</id>>
<br>
<<click "[+]">><<set $pcAgl++>><<replace "#stats-agl">><<print $pcAgl>><</replace>><</click>> |
<<click "[-]">><<set $pcAgl-->><<replace "#stats-agl">><br><<print $pcAgl>><</replace>><</click>></center>
</p>
Comments
Don't use
<<id>>
(or<<class>>
) as they're deprecated. Simply use the appropriate HTML tag with either theid
and/orclass
attributes.Don't use characters which are not alphanumerics, hyphens, or underscores as part of a CSS/DOM identifier (i.e. don't do this: "
stats-$Sklpoints
").You're doing the (in|de)crements of your
$Sklpoints
backwards.Your paragraphs incorrectly use the same
id
. Within a page, all IDs must be unique.It would be cleaner to do all of the $variable initialization at the top.
You're probably also going to want some range checks against the point pool, when incrementing stats, and each stat, when decrementing them (in the example, the pool is clamped to
0
while each stat is clamped to1
).Try something like this: (I assume you're doing this with
nobr
)As TheMadExile explained in point 4, the HTML specification itself requires that all tag id's within a page must be unique.
So having two (or more) paragraph tags with the same ID within your page makes that page invalid HTML and there is no way of knowing exactly what the users browser (brand/version) is going to do about it. You telling people to do otherwise Dazakiwi38 is not a good idea.
If you wish to apply that set of CSS rules to more than one paragraph within a page then you should change your code to something like the following: And change your CSS from being ID based to being CLASS based:
Thanks for your post greyelf. I wasn't purposely trying to contradict MadExile, im still learning. But your words have cleared up the differences between and ID and classes, I thought they did the same thing more or less. Sorry if i was misleading people with my previous post. The reason i mentioned it was i said nothing about the stylesheet originally and that's why i mentioned it. I misunderstood what Exile meant by all ID's have to be unique. I thought he only meant per the code he wrote up.
Okay, so now i know duplicate ID's can make a html page invalid, use classes instead for something like this.
Well at least others in the learning boat, will pick something up from this thread.
Thanks for your suggestion with the class example.