I need help with the Select Option.....

This is a discussion on "I need help with the Select Option....." within the JavaScript Forum section. This forum, and the thread "I need help with the Select Option..... are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 19th, 2003, 03:36
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
I need help with the Select Option.....

Ok, I am building a huge script. It is going to be for a customizeable pc page. They want it done in JavaScript so that is all good. What I don't know how to do is this. How do I set the Options on a select field equal to something. Then take what it is equal too and send it to be added. What I have come up with is a big mess. Once I get all the select fields turned into variables I am good. I can do all that, it's just getting these select fields read and sent to be added. If you would like to see the coding I have I will be more than glad to email it to you. Thanks again.

  #2 (permalink)  
Old Nov 19th, 2003, 04:57
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
When you say 'send to be added' are you sending the form values to a server-side script? Rather than email the code, posting the page to some temp place that we could look at it would make it easier for everyone to help.
  #3 (permalink)  
Old Nov 19th, 2003, 06:34
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
well I am not using any server side scripting for this. What I am doing is starting the script declaring all my variables. Then I add all of these variables up and display the sum on the bottom of the page. What I can't figure out is how I make the different Options in a drop down box equal a different value for that variable so that I can edit the form accordingly.

F.E.-
If I had a drop down list with 3 different options:
20 gig HD - $50
40 gig HD - $100
60 gig HD - $150

Then.. I will have a variable called hardDrive for example. When I use the drop down box to select a 60 gig Hard drive, I want that option to change the variable to "150". That way, when you add the total price you get what you are looking for. I hope this helps you understand it better. I know I have to add a submit button...
  #4 (permalink)  
Old Nov 19th, 2003, 07:08
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
with a SELECT you can set values for each option other than what's displayed:

Code: Select all
<option value="100">40 gig HD - $100</option>
<option value="150">60 gig HD - $150</option>
etc

on the SELECT use the onChange event to call the function that adds the different prices up, that way it'll update the price every time they change an option without having to hit a submit button.

Instead of using variables for each price just use the value of the currently selected option of that SELECT, like if you've got SELECT NAME="hardDrive" you'd get the current value with:
Code: Select all
hardDrive.options[hardDrive.selectedIndex].value
  #5 (permalink)  
Old Nov 19th, 2003, 07:42
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
I am sorry.. Let me post this code and if you can edit it showing me how to use the onChange and the Others I would appreciate it. I am very new to Javascript. Thanks a bunch. Ohh, and I don't need one made for memory stick, I can make all the others myself if someone can show me how to use what Catalyst said.


<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
var hardDrive = 100;
var memoryStick = 200;
add = hardDrive + memoryStick;
document.write("$" + add);
</SCRIPT>




<SELECT NAME="hardDrive">
<OPTION VALUE="200">20 gig Hard Drive</OPTION>
<OPTION VALUE="300">40 gig Hard Drive</OPTION>
<OPTION VALUE="400">60 gig Hard Drive</OPTION>
<OPTION VALUE="500">80 gig Hard Drive</OPTION>
</SELECT>
</BODY>
</HTML>
  #6 (permalink)  
Old Nov 19th, 2003, 08:49
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
This will give you an idea. BTW, the innerHTML bit is not Opera/NS compatible, I put it together just for the example.

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
	<script language="JavaScript" type="text/javascript">
	function doCalculate()
		{
		var curHDD
		var curMonitor
		
		switch (document.frmPcOptions.optHDD.value)
			{
			case "20GB":
				curHDD = 100
				break
			
			case "40GB":
				curHDD = 130
				break
				
			case "60GB":
				curHDD = 150
				break
			
			default:
				curHDD = 0
				break
			}
			
		switch (document.frmPcOptions.optMonitor.value)
			{
			case "17TFT":
				curMonitor = 120
				break
			
			case "17CRT":
				curMonitor = 80
				break
			
			default:
				curMonitor = 0
				break
			}
			
		inner = document.getElementById("Price");
		inner.innerHTML = "Total: " + (curHDD + curMonitor)
		}
	</script>
</head>

<body>

<form name="frmPcOptions">
	HDD: 
	<select name="optHDD" onChange="doCalculate()">
		<option value="">Select a HDD</option>
		<option value="20GB">20GB - $100</option>
		<option value="40GB">40GB - $130</option>
		<option value="60GB">60GB - $150</option>
	</select>
	
	

	
	Monitor:
	<select name="optMonitor" onChange="doCalculate()">
		<option value="">None</option>
		<option value="17TFT">17" TFT - $120</option>
		<option value="17CRT">17" CRT - $80</option>
	</select>
</form>

<div id="price">Total: $0</div>
</body>
</html>
HTH
u2o
  #7 (permalink)  
Old Nov 19th, 2003, 14:34
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
thank you so much for your help. I really appreciate it.
Closed Thread

Tags
help, select, option

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
chained select box dependable select thenamenoonehastaken JavaScript Forum 0 Feb 8th, 2008 05:49
Option values AdINo Web Page Design 3 Jul 6th, 2007 10:09
Option values AdINo JavaScript Forum 2 Jul 5th, 2007 18:48
How to put bookmark option in my website lekha Starting Out 1 May 12th, 2007 11:47
Drop Down Default Option kal PHP Forum 2 Feb 13th, 2006 07:43


All times are GMT. The time now is 19:13.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43