...

View Full Version : Slected Items in form not doing desired functions



theatreus
11-10-2010, 06:36 PM
Ill tell you the story and then simplify it

ok i have a computer site that you can build your own computer and whatnot but i just recently thought about how not everyone knows which parts are needed in a computer... my first design of the site had the name of the part in the select box as default but now i removed the name of each part outside of the select boxes but the problem now is i need some type of onLoad event to happen when the page loads to call out the functions that are associated with the selected boxes......

i have 2 fuctions in an external js file

function swapImage(sel,id){
document.getElementById(id).src = sel.value.split('#')[1];
}

and


function Calculate(){
var a = parseFloat(document.comp.caseselect.value.split('#')[0]);
var b = parseFloat(document.comp.powersupply.value.split('#')[0]);
var sum = a+b;
document.getElementById("total").innerHTML = '$'+sum;
}

when someone selects an item it adds the price to the price of other selected items and shows the total price elsewhere on the page... also shows a picture of the selected item on the page..

im just going to show the first select box to show you how all my select boxes are written


<p align="left">CASE</p>
<center>
<select name="caseselect" style="width:625px" onchange="Calculate(); swapImage(this,'caseimg');">
<option value="50#COOLER MASTER Elite 310red.jpg" selected="1">COOLER MASTER Elite 310 Red ($50.00)</option>
<option value="50#COOLER MASTER Elite 310blue.jpg">COOLER MASTER Elite 310 Blue ($50.00)</option>
<option value="50#COOLER MASTER Elite 310orange.jpg">COOLER MASTER Elite 310 Orange ($50.00)</option>
<option value="50#COOLER MASTER Elite 310silver.jpg">COOLER MASTER Elite 310 Silver ($50.00)</option>
</select>
*not that it matters but yes there is an ending center in my html but its at the end of the group

the image is sent here

<img src="start.jpg" id="caseimg" />
and the price is sent here

<span style="color:black; font-size:20pt">YOUR PRICE UPDATE</span><br />
<span id="total" style="color:white; font-size:32pt">$0 Nothing Selected</span>

code works perfectly fine ONCE YOU SELECT SOMETHING ELSE but i need it to work when the page loads

Philip M
11-10-2010, 07:17 PM
You can simply fire a set of functions when the page loads.


<script type="text/javascript">
window.onload = function() {
functionOne();
functionTwo();
}
</script>

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

theatreus
11-10-2010, 07:31 PM
You can simply fire a set of functions when the page loads.


<script type="text/javascript">
window.onload = function() {
functionOne();
functionTwo();
}
</script>

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

believe it or not i have tried that and i even did it on my own lol no help but the problem with that is that it calculates but not swapimage

theatreus
11-10-2010, 07:48 PM
i know what i can do... ill just change the start img in the html to just load the first selection picture instead of trying to use JS which i wish i could use instead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum