/    Sign up×
Community /Pin to ProfileBookmark

Help! Form needing javascript code

Hi there,

I am new to javascript, and I am working on an adobe acrobat form and I need to input a javascript code, and I have no idea where to begin. I was wondering if anyone can help me or point me in the right direction?

Basically, in my form, there are 3 fields for beneficiary names, we’ll call them “ben1” “ben2” and “ben3”, with a percentage allotted field right next to them. The “X” represents the value that the user needs to input.

ben 1: X % percentage allotted (value can’t exceed 100%)
ben 2: X % percentage allotted (value can’t exceed 100%)
ben 3: X % percentage allotted (value can’t exceed 100%)

For each beneficiary, I want there to be a restriction of 100% as the maximum value they can input. BUT, here’s the issue I’m having. I want the total of all three beneficiaries to equal 100%, not more or less. For example, below, I inputted 3 figures….if all of these values are added together, the value equals more than 100%. Is there a way of doing this, where regardless of whether or not there is one beneficiary, two or all three, that the percentages equal 100% based on the amounts that are filled in? And, I want to make sure the values inputted aren’t less than 100% either.

ben 1: 50 % percentage allotted (value can’t exceed 100%)
ben 2: 40 % percentage allotted (value can’t exceed 100%)
ben 3: 30 % percentage allotted (value can’t exceed 100%)

My question is, what is the best way of achieving the results I would like? Is there anyone who can help me or offer me some advice, I would really appreciate it.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@pactor21Nov 01.2011 — Check THIS jsFiddle out.
Copy linkTweet thisAlerts:
@007JulienNov 02.2011 — A prototype to improve with cursors and without this ugly and ineffective button...
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>Date format</title>
<style type="text/css">
#pge {display:block;width:400px;margin:0 auto;}
.grp {font-family:"courier new"}
.grs {padding:0px;background-color:#999;font-size:6px;}
.ble {padding:0px;background-color:#039;font-size:6px;}

</style>
</head>
<body>
<div id="pge">
<table><tr>
<td class="lbl">Ben1<br>Ben2<br>Ben3</td>
<td><input id="btm0" type="button" value="-" onclick="chg(0,-1)"><br><input id="btm1" type="button" value="-" onclick="chg(1,-1)"><br><input id="btm2" type="button" value="-" onclick="chg(2,-1)"></td>
<td id="rsl" class="grp" width="140px"></td>
<td><input id="btp0" type="button" value="+" onclick="chg(0,1)"><br><input id="btp1" type="button" value="+" onclick="chg(1,1)"><br><input id="btp2" type="button" value="+" onclick="chg(2,1)"></td>
</tr></table>
</div>

<script type="text/javascript">
var tab=[20,50,30];
function chg(a,d){var b=(a+1)&#37;3,c=(a+2)%3,t=tab[a],u=tab[b],v=tab[c];
if (-1<tab[a]+d && tab[a]+d<101) tab[a]+=d;
if (-1<tab[b]-d && tab[b]-d<101) tab[b]-=d;
else if (-1<tab[c]-d && tab[c]-d<101) tab[c]-=d;
aff(tab,'grs');
}

function aff(o,c){var i,g='<span class="grp">',s=0,t;
for (i=0;i<o.length;i++) {
g+='<span class="'+c+'" style="padding-left:'+Math.ceil(o[i])+'px" height="5px"></span> '+Math.round(o[i])+'%';
g+='<br>';}

g+='</span>';
document.getElementById('rsl').innerHTML=g;
}
aff(tab,'grs');
</script>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@007JulienNov 02.2011 — A progress...
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>Date format</title>
<style type="text/css">
#pge {display:block;width:400px;margin:0 auto;}
.grs {padding:0px;background-color:#999;font-size:6px;}
.ble {padding:0px;background-color:#039;font-size:6px;}
a {text-decoration:none;font-weight:bold;color:#000}
</style>
</head>
<body>
<div id="pge">
<table><tr>
<td class="lbl" width="40px;">Ben1<br>Ben2<br>Ben3</td>
<td><a href="javascript:chg(0,-5)">&#171;</a>&nbsp;<a href="javascript:chg(0,-1)">&#8249;&nbsp;</a><br><a href="javascript:chg(1,-5)">&#171;</a>&nbsp;<a href="javascript:chg(1,-1)">&#8249;&nbsp;</a><br><a href="javascript:chg(2,-5)">&#171;</a>&nbsp;<a href="javascript:chg(2,-1)">&#8249;&nbsp;</a></td>
<td id="rsl" class="grp" width="150px"></td>
<td><a href="javascript:chg(0,+1)">&#8250;</a>&nbsp;<a href="javascript:chg(0,5)">&#187;&nbsp;</a><br><a href="javascript:chg(1,+1)">&#8250;</a>&nbsp;<a href="javascript:chg(1,+5)">&#187;&nbsp;</a><br><a href="javascript:chg(2,+1)">&#8250;</a>&nbsp;<a href="javascript:chg(2,+5)">&#187;&nbsp;</a></td>
</tr></table>
</div>

<script type="text/javascript">
var tab=[20,50,30];
function chg(a,d){var b=(a+1)&#37;3,c=(a+2)%3,t=tab[a],u=tab[b],v=tab[c];
if (-1<tab[a]+d && tab[a]+d<101) {tab[a]+=d;
if (-1<tab[b]-d && tab[b]-d<101) tab[b]-=d;
else if (-1<tab[c]-d && tab[c]-d<101) tab[c]-=d;}
aff(tab,'grs');
}
function aff(o,c){var i,g='<span>',s=0,t;
for (i=0;i<o.length;i++) {
g+='<span class="'+c+'" style="padding-left:'+Math.ceil(o[i])+'px" height="5px"></span>&nbsp;'+Math.round(o[i])+'%';
g+='<br>';}

g+='</span>';
document.getElementById('rsl').innerHTML=g;
}
aff(tab,'grs');
</script>
</body>
</html>[/code]

An input type hidden with the tab.toString() value is enough to send the tree values...
×

Success!

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