/    Sign up×
Community /Pin to ProfileBookmark

Onclick to add to multiple numbers

I am new to javascript, so bear with me. I have three embedded for() loops written in php, which echo code in javascript. The first two loops contain header-type text. The third loop contains a textbox which holds a numeric value specified by a variable. Something like this:

[code=php]
echo”var theVar0 = 100;”;
echo”var theVar1 = 123;”;
echo”var theVar2 = 198;”;
echo”var theVar3 = 129;”;
for($L1=0; $L1<3; $L1++){
echo”document.write(‘<br>HEADER 1’);n”;
for($L2=0; $L2<3; $L2++){
echo”document.write(‘<br>HEADER 2’);n”;
for($L3=0; $L3<3; $L3++){
echo”document.write(‘$<input type=”text” name=””.$L3.”_name” value=”‘+theVar”.$L3.”+'”>’);n”;
}
}
}
[/code]

I need a way of making the values inside of the boxes change by 1% of their value when a button is clicked. Something like a button, which when pressed would call a function to perform “theVarX = theVarX + 0.01*theVarX”.

This must be possible using onClick (I can’t use <input> because this is all within a form), but I don’t know how.

Any ideas?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

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