1,105,221 Community Members

Given Values calculate in Percentage

Member Avatar
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi all friends,

As per the below mentioned code, the given No of votes should calculate in percentage and entry per field should not exceed from 100%.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
    function test(vote) {

    var a=document.getElementById(vote).value;

//  var z= document.getElementById(quantity).value;
var t=0;
        for(i=0;i<4;i++)
        {

            j= i + 1;
          charges = 'vote'+ j;
            //alert(amountdiv);
            if(document.getElementById(charges).value != 0){
            t = parseInt(t) + parseInt(document.getElementById(charges).value);
        }
        }
        document.getElementById('other').value=t;

    }
</script>


</head>

<body>

    <form method="post" action="" name="voting" onSubmit="return validate(this);">
    <table width="614" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="160">&nbsp;</td>
      <td>voter total count</td>
      <td><input type="text" name="quantity" value="20301091.00" id="quantity"  /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      </tr>
    <tr>
      <td>Nominees</td>
      <td colspan="2">% Allocation to Max 3 members</td>
      </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      </tr>
    <tr>
      <td>Joann</td>
      <td width="310" valign="middle"><label>
        <input type="text" name="vote[]" id="vote1" onkeyup="test('vote1');" />
      %</label></td>
      <td width="144" valign="middle"><label>
        <input type="text" name="textfield11" />
      </label></td>
    </tr>
    <tr>
      <td>Lee</td>
      <td valign="middle"><label>
        <input type="text" name="vote[]" id="vote2" onkeyup="test('vote2');" />
      %</label></td>
      <td valign="middle"><label>
        <input type="text" name="textfield12" />
      </label></td>
    </tr>
    <tr>
      <td>Aab</td>
      <td valign="middle"><label>
        <input type="text" name="vote[]" id="vote3" onkeyup="test('vote3');" />
      %</label></td>
      <td valign="middle"><label>
        <input type="text" name="textfield13" />
      </label></td>
    </tr>
    <tr>
      <td>Neon</td>
      <td valign="middle"><label>
        <input type="text" name="vote[]" id="vote4" onkeyup="test('vote4');" />
      %</label></td>
      <td valign="middle"><label>
        <input type="text" name="textfield14" />
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>Total shows as per total count </label></td>
      <td><input type="text" name="totalvotes" id="other" readonly="readonly" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      </tr>
    </table>

    </form>
</body>
</html>

--
Kind Regards

LastMitch
Deleted Member
 
0
 

the given No of votes should calculate in percentage and entry per field should not exceed from 100%.

Can you explain a little more what is the issue and what error you got. It's much easier if you do have an error so it's much easier to pinpoint the error.

Member Avatar
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for getting back,

  1. in left column i will enter data in percent, and at right column percent will calculate as per given total voter count, means that right column should display 20% * total voter count. but remember that entered percent value should not exceed more than 100%.
  2. no of voters or total fields do not exceed more than 3 means 3/4 only.

--
Kind Regards

LastMitch
Deleted Member
 
0
 

in left column i will enter data in percent,

That's working fine. I know that.

right column percent will calculate as per given total voter count,

You don't even have a code for that?

456

It's not gonna calulate at all without a right column everything is calucate from the left column?

no of voters or total fields do not exceed more than 3 means 3/4 only.

I thought you wrote a row calculation first then everything makes more sense.

For example:

50 voter total count 
20% voted Joann
10% percent meaning there's 90% out of 100% left


       Right Column   Left Column
       ------------   -----------
Joann:     20%      |     10


50 voter x 20% voted for Joann = 10

50 x 20% = 10

You didn't explain the math equation at all?

It's like rewriting the whole your code from scratch?

There's nothing do work on here that I can be added something.

Attachments
Member Avatar
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

so much thanks to revert me... i dont know i am stuck right now, but i believe that my problem will solved as per attached file for your kind consideration where i have mentioned required column with yellow background.

Attachments votes.zip (10.34KB)
Member Avatar
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I think that i am not able to learn more using forums, what should be done with this problem seems only can see not solve it.

LastMitch
Deleted Member
 
0
 

I think that i am not able to learn more using forums, what should be done with this problem seems only can see not solve it.

I got no idea what you talking about.

I don't download files. You have to post the code.

I tell that to everyone who I help to post the code.

I don't want you to get upset.

People comes to forums to learn not expecting people to do all the work.

I look over the code last night and you really didn't do it correctly meaning the calculation.

I mean writing a little code and helping out to a certain extend is fine but writing a whole code and doing the calculation at the same time is like working.

That's a bit too much work for me or anyone to do.

What I post is the correction calculation for this calcuator to work.

In the end, it won't go over 100% it will stop because each row has a equation to prevent being over 100%

Member Avatar
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Okay.... :)
i have coded a example budget as mentioned, i know its hard coded but now require if total number (count) of fields filled then display 4 in below given field (id=rt5) with red background else 3 with yellow background and process further, in a simple way i wana total 3/4 fields should > 0 remaining field disable or should not calculated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<title>Untitled Document</title>
<script language="javascript" type="text/javascript">

/* budget form has controls for:
   a# - acct names, c# - acct amts, r# - % in each acct
   ct - amount to be spent, rt - total % allocated */
/* checked with jslint 2009 02 22 */
// set globals here
var maxbud=100;var bct;var brt;var ac=[];var bc=[];var br=[];
var to=99;var max=4; //cookie time(days), # of accts
function isDig(entry){
  validChar='0123456789';strlen=entry.length;
  if(strlen<1){alert('Enter Something!');return false;}
  for(idx=0;idx<strlen;idx++){
    if(validChar.indexOf(entry.charAt(idx))<0){
      alert("Use digits only!");return false;} }
  return true;}
function budPrint(el){
  budObj=document.getElementById(el).innerHTML;
  win=window.open();self.focus();win.document.open();
  win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
  win.document.write('body, td {font-family:Verdana;font-size:10pt}');
  win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
  win.document.writeln(budObj);
  win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
  win.document.close();win.print();win.close();}
function bakeCookie(name,value){
  args=arguments;argc=args.length;expires=(argc>2)?args[2]:null;
  path=(argc>3)?args[3]:null;domain=(argc>4)?args[4]:null;
  secure=(argc>5)?args[5]:false;expDate=new Date();day=24*60*60*1000;
  if(expires){expDate.setTime(expDate.getTime()+expires*day);}
  document.cookie=name+"="+escape(value)+
    ((expires===null)?"":("; expires="+expDate.toUTCString()))+
    ((path===null)?"":("; path="+path))+
    ((domain===null)?"":("; domain="+domain))+
    ((secure===true)?"; secure":"");}
function eatCookieVal(name){
  endstr=document.cookie.indexOf(";",name);
  if(endstr===-1){endstr=document.cookie.length;}
  return unescape(document.cookie.substring(name,endstr));}
function eatCookie(name){
  arg=name+"=";alen=arg.length;clen=document.cookie.length;idx=0;
  while(idx<clen){j=idx+alen;
    if(document.cookie.substring(idx,j)===arg){return eatCookieVal(j);}
    idx=document.cookie.indexOf(" ",idx)+1;if(idx===0){break;}
  }}

function budFocus(){document.getElementById('ct').focus();}
function budReadCookies(){
  c=eatCookie("bct");if(c===undefined){budClr();}
  for(i=1;i<=max;i++){
    ac[i]=eatCookie('a'+i);br[i]=parseFloat(eatCookie('r'+i),10);}
  bct=parseFloat(eatCookie("bct"),10);}
function budWriteCookies(){bakeCookie("bct",bct,to);
  for(i=1;i<=max;i++){
    bakeCookie('a'+i,ac[i],to);bakeCookie('r'+i,br[i],to);} }
function budRead(){
  for(i=1;i<=max;i++){
    ac[i]=document.getElementById('a'+i).value;
    ival=document.getElementById('r'+i).value;
    if(!isDig(ival)){ival=0;}
    br[i]=parseFloat(ival,10);}
  ival=document.getElementById('ct').value;
  if(!isDig(ival)){ival=maxbud;}
  bct=parseFloat(ival,10);}
function budWrite(){ // sets form display
  for(i=1;i<=max;i++){
    document.getElementById('c'+i).style.background='yellow';
    document.getElementById('a'+i).value=ac[i];
    document.getElementById('c'+i).value=bc[i];
    document.getElementById('r'+i).value=br[i];}
  document.getElementById('ct').value=bct;
  document.getElementById('rt').value=brt;

  }
function budRound(x,y){s=Math.pow(10,y);x=Math.round(x*s)/s;
  x+='';s=x.indexOf('.');if(s==-1){x+=".000";}else{x+="000";}
  s=x.indexOf('.');x=x.substr(0,s+3);return x;}
function budCalc()
    {
    budRead();brt=0;
  for(i=1;i<=max;i++){brt+=br[i];bc[i]=budRound(bct*br[i]/100,2);}
  back='yellow';if(brt>100){back='red';}
  document.getElementById('rt').style.background=back;
  budWriteCookies();budWrite();}





</script>
</head>

<body>

<h2 id="bfx">&nbsp;</h2>
<form id="pBudForm" class="fancy4" action="" onsubmit="return false;">
<fieldset><legend>Pro Forma Budget Calculator</legend><table><tr>
<th colspan="2">Red = Over budget | Yellow = read only zone</th></tr><tr>
<td><ul class="nodec">
<li class="just"><strong>Budget Amount:</strong></li>
<li><input id="a1" class="box190" type="text" value="Account Name"/></li>
<li><input id="a2" class="box190" type="text" value="Account Name"/></li>
<li><input id="a3" class="box190" type="text" value="Account Name"/></li>
<li><input id="a4" class="box190" type="text" value="Account Name"/></li>
</ul></td><td><ul class="nodec">
<br />
<li><input id="rt" class="box25c" type="text" readonly="readonly"/> %</li>
<li><input id="r1" class="box25" type="text"/> %</li>
<li><input id="r2" class="box25" type="text"/> %</li>
<li><input id="r3" class="box25" type="text"/> %</li>
<li><input id="r4" class="box25" type="text"/> %</li>
</ul></td><td><ul class="nodec">
<br />
<li>$ <input id="ct" class="box70" type="text"/></li>
<li>$ <input id="c1" class="box70c" type="text" readonly="readonly"/></li>
<li>$ <input id="c2" class="box70c" type="text" readonly="readonly"/></li>
<li>$ <input id="c3" class="box70c" type="text" readonly="readonly"/></li>
<li>$ <input id="c4" class="box70c" type="text" readonly="readonly"/></li>
</ul></td></tr>
<tr>
  <td>&nbsp;</td>
  <td><label>
   <input id="rt5" class="box25d" type="text" readonly="readonly"/>
  </label></td>
  <td>&nbsp;</td>
</tr>
<tr><td class="just" colspan="3">
<button onclick="budCalc();budFocus();">Calc!</button>

</td></tr></table>
</fieldset></form>
<p>&nbsp;</p>


</body>
</html>
LastMitch
Deleted Member
 
0
 

i know its hard coded but now require if total number (count) of fields filled then display 4 in below given field (id=rt5) with red background else 3 with yellow background and process further, in a simple way i wana total 3/4 fields should > 0 remaining field disable or should not calculated.

48

What kind of a calucator is this?

Is this a investment calucator?

If so, then there is some serious issue.

You can't predict or estimate how a stock will do over time.

What kind of a budget is this?

If this looks like an budget calculator it should include an allotment.

In your code it doesn't separate it by percentage at all.

It's just adding and subtract without calculating the allotment by percentage.

This is the only thing I came up.

Regarding about a budget or investment calucator it adds and minus like your but without percentage
(You can add percentage on here):

<script language="javascript" type="text/javascript">
function round(numbers) {
tresult = Math.round(numbers*Math.pow(2,1))/Math.pow(2,1);
tresult -= 0;
return (tresult == Math.floor(tresult)) ? tresult: ((Math.floor(tresult)) ? tresult: tresult);
}

function budget(form) {
stock = form.shares.value * 1;

buyprice = form.buyprice.value;
increase = form.increase.value * 1;

sellprice = form.sellprice.value;
decrease = form.decrease.value * 1;

bought = round(parseFloat(stock * buyprice) + increase);
sold = round(parseFloat(stock * sellprice) - decrease); 
result = round(sold - bought);

form.buycost.value  = "$ " + bought;
form.sellcost.value = "$ " + sold;
form.result.value = "$ " + result;
}
//  End -->
</script>

<center>
<form name='budgetform'>
<table border=1>
<tr>
<td align=center><font face="Times New Roman" size="-10">Stock</td>
<td><input type=text name=shares value="100" size=4></td>
</tr>
<tr>
<td align=center><font face="Times New Roman" size="-10">Buy Price</td>
<td><input type=text name=buyprice size=4></td>
<td align=center><font face="Times New Roman" size="-10">Increase</td>
<td><input type=text name=increase size=4></td>
<td align=center><font face="Times New Roman" size="-10">Total Buy</font></td>
<td align=center><input type=text name=buycost size=4></td>
</tr>
<tr>
<td align=center><font face="Times New Roman" size="-10">Sell Price</td>
<td><input type=text name=sellprice size=4></td>
<td align=center><font face="Times New Roman" size="-10">Decrease</td>
<td><input type=text name=decrease size=4></td>
<td align=center><font face="Times New Roman" size="-10">Total Sold</font></td>
<td align=center><input type=text name=sellcost size=4></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=button name=calc value="Calculate" onClick="javascript:budget(this.form)">
</td>
<td align=center><font face="Times New Roman" size="-10">Result</font></td>
<td align=center><input type=text name=result size=4></td>
</tr>
</table>
<p>
</form>
</center>
Attachments
Member Avatar
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

So nice to hear from you again,

okay,.... let say Calculator works fine.... terminate here.

after calculation can you please tell me how to submit this form to next page (let say if by action), because i will insert calculated data into php/msql db, or can submit this form by php header location.

Please clarify.

Thanks alot!!!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article