Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2012, 02:57 AM   PM User | #1
EmoAeden
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
EmoAeden is an unknown quantity at this point
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.
EmoAeden is offline   Reply With Quote
Old 02-13-2012, 03:19 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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>
xelawho is offline   Reply With Quote
Old 02-14-2012, 07:28 AM   PM User | #3
EmoAeden
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
EmoAeden is an unknown quantity at this point
It works !!!

You have no idea how happy I am right now. If I could, I would have your babies XD
EmoAeden is offline   Reply With Quote
Old 02-14-2012, 08:11 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 02-14-2012, 08:16 AM   PM User | #5
Co1dFusion
New Coder

 
Join Date: Feb 2012
Location: England
Posts: 77
Thanks: 0
Thanked 12 Times in 11 Posts
Co1dFusion can only hope to improve
Is that actualy true? lols anyway
Co1dFusion is offline   Reply With Quote
Old 02-14-2012, 08:27 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 02-14-2012, 03:24 PM   PM User | #7
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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...
xelawho is offline   Reply With Quote
Old 02-14-2012, 09:21 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
alter html, alter javascript, values

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Advertisement
Log in to turn off these ads.