Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- JavaScript for calculation


JuicyScript - 1:33 pm on Nov 24, 2011 (gmt 0)


Hello
I have a JavaScript code that calculates based on your dropdown(select list) selection.What i want is that the results should be capture in my input value field and not just print it out using the div tags.Can someone help me with this?
Here is my code

JavaScript Code
// JavaScript Document
var grade1_aggregrate= new Array();
grade1_aggregrate["None"]=0;
grade1_aggregrate["A"]=1;
grade1_aggregrate["B"]=2;
grade1_aggregrate["C"]=3;
grade1_aggregrate["D"]=4;
grade1_aggregrate["E"]=5;
grade1_aggregrate["F"]=6;

function getGrade1Aggregate()
{
var formGrade1Aggregate=0;
//Get a reference to the form id="aggregateform"
var theForm = document.forms["aggregateform"];
//Get a reference to the select id="grade1"
var selectedGrade1 = theForm.elements["grade1"];
//set formGrade1Aggregate Price equal to value user chose
//For example grade1_aggregrate["None".value] would be equal to 0
formGrade1Aggregate = grade1_aggregrate[selectedGrade1.value];
//finally we return cakeFillingPrice
return formGrade1Aggregate;
}

function calculateTotal()
{
var totalAggregate = getGrade1Aggregate();
//var totalAggregate = getGrade1Aggregate();
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML ="Total Price For Cake $"+totalAggregate;
}


function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}

HTML CODE
<select name="grade1" id="grade1" onchange="calculateTotal()">
<option value="None"></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
</select>
<td width="243" class="td">Overall Aggregate </td>
<input name="aggregrate" type="text" size="10" value="" id="aggregrate" /></td>
<div id="totalPrice"></div>


Thread source:: http://www.webmasterworld.com/javascript/4390670.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com