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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Altering a webpage with Java

    OK, I appologise in advance if this post is long, but I need this answer, as I'm at my wits end.

    So I have this code
    Code:
    function SizeSelect(){
    	if(document.getElementById("JarSize").value=="Small")
    	document.getElementById("JarPrice").innerHTML="3.00"
    	else if(document.getElementById("JarSize").value=="Medium")
    	document.getElementById("JarPrice").innerHTML="5.00"
    	else if(document.getElementById("JarSize").value=="Large")	
    	document.getElementById("JarPrice").innerHTML="7.00"
    }
    Which alters the value of JarPrice, based on which JarSize is selected. Which is the code below here.
    Code:
    <select id="JarSize" onchange="SizeSelect();"> 
    					<option value="Small" >Small</option> 
    					<option value="Medium">Medium</option> 
    					<option value="Large">Large</option> 
    			</select>
    			<span class="price">$<span id="JarPrice">3.00</span></span></div>
    Now for the hard part. I need this piece of code
    Code:
    <a href="javascript:;" onclick="simpleCart.add('name=Mango and Papaya', 'price=5', 'quantity=1');"  class="prod_buy">add to cart</a>
    to be flexible, so that what ever value JarPrice becomes, that 'price=5' becomes the same.

    Now, the first piece of code is in a seperate .js file to the other two parts, which sit inside a regular HTML page. As I said, I'm desperate, as this is the only part of my site that isn't working ATM

    And if you need more information about any part, please don't hesitate to ask, as I will be able to give as much info as I can.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    I simplified it a little (this one was screaming out for a switch) and I think this works but I couldn't test the link. Let me know if not...

    Code:
    <html>
    <head>
    
    </head>
    <body>
    <select id="JarSize" onchange="SizeSelect(this.value);"> 
    					<option value="Small" >Small</option> 
    					<option value="Medium">Medium</option> 
    					<option value="Large">Large</option> 
    			</select>
    			<span class="price">$<span id="JarPrice">3.00</span></span></div>
    <a href="javascript:void(0)" onclick="simpleCart.add('name=Mango and Papaya', 'price='+pri, 'quantity=1');"  class="prod_buy">add to cart</a>			
    <script type="text/javascript">
    var pri="3.00"
    function SizeSelect(val){
    switch(val){
    	case "Small":
    	price="3.00";
    	break;
    	case "Medium":
    	price="5.00";
    	break;
    	case "Large":
    	price="7.00";	
    	break;
    	}
    	pri=price;
    	document.getElementById("JarPrice").innerHTML=price;
    }	
    </script>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It works !!!

    You have no idea how happy I am right now. If I could, I would have your babies XD

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,996
    Thanks
    79
    Thanked 4,433 Times in 4,398 Posts
    What you don't know is that Xelawho is actually a species of wasp that lays its eggs inside of living creatures so that, indeed, the babies hatch inside you. So maybe you shouldn't have offered. <snicker/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    77
    Thanks
    0
    Thanked 12 Times in 11 Posts
    Is that actualy true? lols anyway

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    XelaWho: Quetzaltenango's Leading Culture & Nightlife Magazine
    A place in Guatemala!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Xelajú: The original Quiché maya name for Quetzaltenango, meaning "place at the foot of 10 hills"
    Xelawho: A dumb wordplay on the above ("j" is pronounced "h" in Spanish)

    because I know the uncertainty was eating you all up...

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,996
    Thanks
    79
    Thanked 4,433 Times in 4,398 Posts
    Quote Originally Posted by xelawho View Post
    Xelajú: The original Quiché maya name for Quetzaltenango, meaning "place at the foot of 10 hills"
    Xelawho: A dumb wordplay on the above ("j" is pronounced "h" in Spanish)

    because I know the uncertainty was eating you all up...
    very nice, actually! thanks
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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