Hi, i've modified a Javascript and added a graph to the javascript calculater. Meaning that the numbers you get by the input, will be shown in a graph when push a button.

Problem: I need the value from the first input box, to be the blue in my graph.

What i know: the variable "res1" gives me the correct value that i need for green in my graph

What i've tried: Going systematicaly through every variable, and tested for getting the value from that first box.

What can confuse: It's 2 scripts mixed togheter, where only one is enabled for the purpose. And a simple graph is added in the button of the script.


I love javascript, and been doing it for a long time. But i'm blank on this one.

Any help is higly appreciated

Kind regards

Simon



Code:
<html lang="en">
<head>
<meta charset="utf-8" />
<script src='Chart.min.js'></script>


<script language="javascript" type="text/javascript">
  <!--  
  
//var afrunder=10;
//var pris=2.00;
var res1;
var res2;
var res3;
var res4;
var res5;
var res6;
var res7;
var res8;
var res9;
var res10;
var inputtext;


function SumCalc() 
{
var xx1;
var xx2;
var xx3;
var sSumResultLevetid;
var sSumResultEnd;
var sSumResult;
var sSumResult1;
var iCount;


    xx1=res1; 

//alert(xx1);

    xx2=res2;


    
    
//alert(xx1);
sSumResult1 = "Bemærk at besparelsen er et cirkatal. Hvis du ønsker en mere præcis beregning af netop dine besparelsesmuligheder, så prøv <a href='http://www.elsparefonden.dk/forbruger/minbolig' target='_blank' title='Prøv også vores beregner på Min Bolig'>Min Bolig</a><br />";

sSumResultEnd = "<table class='tiraadvisresult1' border='0'><tr><td class='tiraadvisfortekst'>Hvis du gennemf&oslash;rer projektet, f&aring;r din husstand</td><td class='tiraadvisresult1'>" + Tusindseparator(xx1) + "</td><td class='tiraadvissluttekst'>kr. tilbage i skat,</td></tr></table>";  
sSumResult = "<table class='tiraadvisresult1' border='0'><tr><td class='tiraadvisfortekst1'>og du kan stadig tr&aelig;kke</td><td class='tiraadvisresult1'>" + Tusindseparator(xx2) + "</td><td class='tiraadvissluttekst1'> kr. fra i &aring;r.</td></tr></table>";    
document.getElementById('lblDuSparer1').innerHTML = sSumResultEnd;  
document.getElementById('lblDuSparerLevetid').innerHTML = sSumResult;  


}




function isNotEmpty(field) 
{ 

  var inputStr = field.value; 
  if (inputStr == "" || inputStr == null) 
    { 
    return false; 
    } 

  return true; 
} 


function isConvToNumber(field) 
{ 
alert("isConvToNumber");

  text="";
  var n=0;
  
  if (isNotEmpty(field)) 
    { var inputStr = field.value;
    if (inputStr.length > 20) return false;
    for (var i = 0; i < inputStr.length; i++) 
      {
      var oneChar = inputStr.substring(i, i + 1);
                                                              
      if (oneChar < "0" || oneChar > "9")    
        {
          if (oneChar != ",")
            {
              text=text+",";
            }
          else
            {
            n=n+1;
            if (n>1) return text;
            }  
        }
	 else
	    {
		text=text+oneChar;
		}	
      }

    return text; 
    } 
  return text;
} 

function ConvToJavaNumber(field) 
{
  inputtext = "";
  var n=0;
  if (isNotEmpty(field)) 
    { var inputStr = field.value;
    if (inputStr.length > 20) return false;
    for (var i = 0; i < inputStr.length; i++) 
      {
      var oneChar = inputStr.substring(i, i + 1);
                                                              
      if (oneChar < "0" || oneChar > "9")    
        {
          if (oneChar != ".")
            {
              inputtext=inputtext+".";
            }
          else
            {
            if (oneChar == ".")
              {
                inputtext=inputtext+".";
              }
            else
              {
              n=n+1;
              if (n>1) return inputtext;
              }  
            }  
        }
	 else
	    {
		inputtext=inputtext+oneChar;
		}	
      }
    return inputtext; 
    } 
  return inputtext;
} 


function Tusindseparator(Number){
  Number = String(Number);
  if (Number.split('.').length > 1) return Number;
  else if (Number.length > 3){
    var Mod = Number.length%3;
    var Change = (Mod > 0 ? (Number.substring(0,Mod)) : '');
    for (j=0; j<Math.floor(Number.length/3); j++){
      if (Mod == 0 && j == 0)  Change += Number.substring(Mod+3*j, Mod+3*j+3);
      else Change += "."+Number.substring(Mod+3*j, Mod+3*j+3);
    }
    return Change;
  }
  else return Number;
}

function CalcAll() 
{
Raad_1_onchange(); 
SumCalc();
}

function toggleChildren(obj,DeviceID,noStore) {
      if(DeviceID.length == 0) return;
      //trs = document.all("_" + DeviceID);
      //trs = document.all(DeviceID);
      trs = document.getElementById(DeviceID);
      if(trs.length) {
        //it's an array
        curStyle = trs[0].style.display;
        if(curStyle == "none") {
          newstyle = "inline";
          imgsrc = "bokspilop.gif";
        } else {
          newstyle = "none";
          imgsrc = "bokspilhoejre.gif";
        }
        for(n=0;n<trs.length;n++) {
          trs[n].style.display = newstyle;
        }
        obj.src = "images/" + imgsrc;
      } else {
        //not array
        curStyle = trs.style.display;
        if(curStyle == "none") {
          newstyle = "inline";
          imgsrc = "bokspilop.gif";
        } else {
          newstyle = "none";
          imgsrc = "bokspilhoejre.gif";
        }
        obj.src = "images/" + imgsrc;
        trs.style.display = newstyle;
      }

        if(imgsrc == "bokspilop.gif") {
          document.getElementById("txt"+DeviceID).innerHTML = "Fold ind";
        } else {
          document.getElementById("txt"+DeviceID).innerHTML = "Fold ud";
        }
      //ny if (!noStore) storeView(DeviceID);
      //alert(GetCookie("DeviceToShow"));
 }
 
function popUp(URL) { 
day = new Date(); 
id = day.getTime(); 
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1,width=900,height=675,left = 490,top = 362');"); 
} 
-->
</script>

    
<script language="javascript" type="text/javascript">
<!--
function Raad_1_onchange() 
{
var xx1;
var xx2;
var xx3;
var iPersoner;
var iTimer;
var iCount;
var iCount2;
var iCount3;
var sResult;
var sResult2;
var dUdgift;
var dGammeltFradrag;
var dFradrag;
var dRestFradrag;
var dSparPerCount3;
var dTypeFaktor;
var dBest;
var dAktuelt;
dSparPerCount = 1;
dSparPerCount2 = 1;
dSparPerCount3 = 1;


    iCount =  document.getElementById('Raad_1').value;
    iPersoner = Math.round((iCount));



    dUdgift = document.getElementById('Raad_1_2').value;
    xx2 = iCount2;
    //xx2 = Math.round((iCount2) / afrunder);
    //xx2 = xx2 * afrunder;
    if (dUdgift > 200000) {
        alert("Udgiften skal være mindre end 200000 kr.");
        document.getElementById('Raad_1_2').value = 0;
        dUdgift = 0;
    }

    if (dUdgift < 0) {
        alert("Udgiften skal være positiv");
        document.getElementById('Raad_1_2').value = 0;
        dUdgift = 0;
    }

    dGammeltFradrag = document.getElementById('Raad_1_3').value;

    if (dGammeltFradrag > 200000) {
        alert("Tidligere fradrag skal være mindre end 200000 kr.");
        document.getElementById('Raad_1_3').value = 0;
        dGammeltFradrag = 0;
    }

    if (dGammeltFradrag < 0) {
        alert("Tidligere fradrag skal være positiv");
        document.getElementById('Raad_1_3').value = 0;
        dGammeltFradrag = 0;
    }




    dAktuelt = (iPersoner * 15000) - dGammeltFradrag;

    if (dAktuelt < dUdgift) {
        dFradrag = dAktuelt * 0.326;
    }
    else {
        dFradrag = dUdgift * 0.326;
    }

    dFradrag = Math.round(dFradrag);
    res1 = dFradrag;

    if ((dAktuelt - dUdgift) > 0) {
        dRestFradrag = dAktuelt - dUdgift;
    }
    else {
        dRestFradrag = 0;
    }

    dRestFradrag = Math.round(dRestFradrag);
    res2 = dRestFradrag;

    if (res1 < 0) {
        res1 = 0;
    }
    if (res2 < 0) {
        res2 = 0;
    }


SumCalc();
}




function nulstil() 
{

    document.getElementById('Raad_1').value = 0;
    document.getElementById('Raad_1_2').value = 0;
    document.getElementById('Raad_1_3').value = 0;


CalcAll();

}


// -->




//graph 
function graph()
{
var pieData = [

	{
		value : res1,
		color : "green"
	},
	{
		value : document.getElementById('raad_1_2').value,
		color : "#79bbff"
	}
];
var pieOptions = {
	segmentShowStroke : false,
	animateScale : true
}
    var graph= document.getElementById("graph").getContext("2d");
new Chart(graph).Pie(pieData, pieOptions);
}
</script>

<div id="Panel2">
	



<form name="hurtig" action="hurtigberegner_fradragsberegner_plone.aspx" method="post">

<table class="tiraadmain" summary="Fradragsberegner" width="468">

<tr><td class="tiraadtop">Fradragsberegner</td></tr>
<tr><td class="tiraadkant">
<table class="tiraadindhold" summary="Indtast info og få fradragsoplysninger">

<!--tr><td class="tiraadheader_top" colspan="3">Skoler</td></tr-->

<tr><td colspan="3" class="tiraadtomlinie"></td></tr>

<tr>
	<td colspan="3">
		<table width="100%" summary="" style="DISPLAY: block" id="vis_1">

	                   


			<tr>
				<td class="tiraaduserinfo">Antal personer i din husstand over 18 år</td>
				<td class="tiraaduserselect" style="width: 100px">
					<select id="Raad_1" class="tiraaduserselectstk" onchange="return Raad_1_onchange()" name="Raad_1"> 
                    
							<option value="1" selected="selected">1</option> 
						
							<option value="2">2</option> 
						
							<option value="3">3</option> 
						
							<option value="4">4</option> 
						
							<option value="5">5</option> 
						
							<option value="6">6</option> 
						
                   </select> 
                </td>
				<td class="tiraad_enhed"></td>
			</tr>

            <tr><td colspan="3" class="tiraadtomlinie"></td></tr>

	                   
			<tr>
				<td class="tiraaduserinfo">Samlet udgift i arbejdsløn:</td>
				<td class="tiraaduserselect" style="width: 100px">
					<input type="text" class="tiraadnumerisk"  value="0" name="Raad_1_2" id="Raad_1_2" onkeyup="return Raad_1_onchange()"/>
				</td>
				<td class="tiraad_enhed">kr.</td>
			</tr>

		    <tr><td colspan="3" class="tiraadtomlinie"></td></tr>

	                   
			<tr>
				<td class="tiraaduserinfo">Hvis du allerede har benyttet noget af dit  fradrag for i år,<br />så indtast udgift for arbejdslønnen her: <br /></td>
				<td class="tiraaduserselect" style="width: 100px">
					<input type="text" class="tiraadnumerisk"  value="0" name="Raad_1_3" id="Raad_1_3" onkeyup="return Raad_1_onchange()"/>
				</td>
				<td class="tiraad_enhed">kr.</td>
			</tr>
			
		</table>
	</td>
</tr>
       
<tr><td colspan="3" class="tiraadtomlinie"><hr width="100%" /></td></tr>
                   

<tr>
    <td class="tiraadheader_bund1" colspan="3"><br /><b>Dit håndværkerfradrag</b><br /><br /><span id="lblDuSparer1"></span><span id="lblDuSparerLevetid"></span></td> 
	
    
</tr>
<tr>
	<td class="tiraadheader_bund" colspan="3">
	
<input type="button" class="button" value="Vis graf" onclick="javascript:graph()"/>
<canvas id="graph" width="450" height="250"></canvas>

</td>
</tr>

</table>
</td>
</tr>
</table>
</form>


</div>


<script language="javascript" type="text/javascript">
CalcAll();
</script>

</html>


Chart.min.zip