Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post

    Slected Items in form not doing desired functions

    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
    Code:
    function swapImage(sel,id){
    	document.getElementById(id).src = sel.value.split('#')[1];
    }
    and

    Code:
    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

    Code:
    <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
    Code:
    <img src="start.jpg" id="caseimg" />
    and the price is sent here
    Code:
    <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
    Last edited by theatreus; 11-10-2010 at 06:39 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,078
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    You can simply fire a set of functions when the page loads.

    Code:
    <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.

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Philip M View Post
    You can simply fire a set of functions when the page loads.

    Code:
    <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

  • #4
    New Coder
    Join Date
    Nov 2010
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •