PDA

View Full Version : simple dropdown box to value script



*DEAD*
Nov 8th, 2005, 11:34 AM
hi, i know nothing of java and need some serious help. i was making a php script for an computing assignment and i just found from my partner that its not going to work. instead, i need a java script that will present the viewer with several dropdown boxes. the dropdown boxes will contain different products, each with different value. At the bottom, i need the script to add up all the values and display it in a text field. If anyone can help by making a quick example i could easily build on id much appretiate it.

*DEAD*
Nov 8th, 2005, 02:49 PM
ok hacked up something based on several examples around the web. it doesnt work though. im using dream weaver as my editor if that means anything. could someone please take a look at this and see if they can figure this out. please remember i have never used java script before

<!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>Components</title>

<SCRIPT LANGUAGE="JavaScript">
function add() {
var mobo = eval(Components.parts.motherboard.value)
var proc = eval(Components.parts.processor.value)
var ramm = eval(Components.parts.ram.value)
var cddd = eval(Components.parts.cd.value)
var hddd = eval(Components.parts.hd.value)
var gfxx = eval(Components.parts.gfx.value)
var sfxx = eval(Components.parts.sfx.value)
var cass = eval(Components.parts.cass.value)
var xtra = eval(Components.parts.xtra.value)
var tota = mobo + proc + ramm + cddd + hddd + gfxx + sfxx + cass + xtra
Components.parts.total.value=custRound(tota,2);
}
</script>

</head>

<body>
<CENTER>
<FORM NAME="parts">
<table border="1">
<tr>
<td>Mother Board</td>
<td>
<select name="motherboard">
<option value="200" selected>ASUS Nforce 4 K8N4-e - $200</option>
<option value="300">OZ MoBo (Recommended) - $300</option>
</select>
</td>
</tr>
<tr>
<td>Processor</td>
<td>
<select name="processor">
<option value="1200" selected="selected">AMD X2 4800 - $1200</option>
<option value="1500">OZ processor (Recommended) - $1500</option>
</select>
</td>
<tr>
<td>Ram</td>
<td>
<select name="ram">
<option value="200" selected="selected">Cossair XMS High Perfomance - $200</option>
<option value="500">OZ ram (Recommended) - $500</option>
</select>
</td>
</tr>
<tr>
<td>DVD\CD burner</td>
<td>
<select name="cd">
<option value="80" selected="selected">Sony DVD/CD burner - $80</option>
<option value="100">OZ DVD/CD griller (Recommended) - $100</option>
</select>
</td>
</tr>
<tr>
<td>Hard Drive</td>
<td>
<select name="hd">
<option value="400" selected="selected">Western Digital 148 GB 10000 rpm Raptor - $400</option>
<option value="2000">OZ Disk 100 Kigilobytes (Recommended) - $2000</option>
</select>
</td>
</tr>
<tr>
<td>Graphics Card</td>
<td>
<select name="gfx">
<option value="900" selected="selected">Geforce 7800 GTX - $900</option>
<option value="1600">OZ GFX (Recommended) - $1600</option>
</select>
</td>
</tr>
<tr>
<td>Sound Card</td>
<td>
<select name="sfx">
<option value="350" selected="selected">Audighy X-Fi- $350</option>
<option value="600">OZ Sonic (Recommended) - $600</option>
</select>
</td>
</tr>
<tr>
<td>Case</td>
<td>
<select name="cass">
<option value="100">Big Shiny Case with Neon Cooling - $100</option>
<option value="300">OZ BOX Classic (recommended) - $300</option>
</select>
</td>
</tr>
<tr>
<td>Extras</td>
<td>
<select name="xtra">
<option value="350">OZ BOX accessories (mouse, keyboard, etc.) - $350</option>
<option value="0">none - $0</option>
</select>
</td>
</tr>
<tr>
<td>Total</td>
<td>
<input type="text" name="total">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" value="Calculate" onClick="add()" name="calc">
</td>
</tr>
</table>
</FORM>
</CENTER>
</body>
</html>

*DEAD*
Nov 8th, 2005, 03:10 PM
never mind i got it working