Current location: Hot Scripts Forums » General Web Coding » JavaScript » Question regarding JavaScript


Question regarding JavaScript

Reply
  #1 (permalink)  
Old 10-07-08, 05:24 PM
MrMinde MrMinde is offline
New Member
 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question regarding JavaScript

Hi,

I am new around and new to Javascripting, though I have had some years on my back with HTML and some PHP.

I am trying to create a drop-down menu, where each displayed name has a defined value.

For example
<option value=''>Adamstua</option>

I want that spesific option to have a number signed to it, like for example 670.

In my second drop down list, I chose for example <option>blabla</option> option blabla has a value of 100.

So depending on whether or not the second option is used or not, I want the website to calculate me the differences between the selected options?

If it helps any I am trying to create something similar to a price calculator with various options, and where each option makes a difference to the total price shown.

Thank you.

- Johnny
Reply With Quote
  #2 (permalink)  
Old 10-08-08, 03:41 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
document.getElementById("ID of list").value will bring in the value of the selection into javascript:

example:
Code:
<select onChange="alert(document.getElementById('myList').value)" id="myList">
  <option value="100">I'm Worth 100 Points</option>
  <option value="200">I'm Worth 200 Points</option>
  <option value="400">I'm Worth 400 Points</option>
  <option value="800">I'm Worth 800 Points</option>
</select>
Reply With Quote
  #3 (permalink)  
Old 10-08-08, 07:17 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
There are many ways you can go about this:

Here are a couple examples that I can think of:
Javascript Code:
  1. <script>
  2. var value1="";
  3. var value2="";
  4. function Calculate_difference()
  5. {
  6.  document.getElementById("results").innerHTML = value1 - value2;
  7.  }
  8. </script>
  9. <span>Value 1 </span>
  10. <select onchange="value1=this.value;">
  11. <option value="">Make a selection.</option>
  12. <option value="1000">1000 points</option>
  13. <option value="2000">2000 points</option>
  14. <option value="3000">3000 points</option>
  15. <option value="4000">4000 points</option>
  16. <option value="5000">5000 points</option>
  17. <option value="6000">6000 points</option>
  18. <option value="7000">7000 points</option>
  19. <option value="8000">8000 points</option>
  20. <option value="9000">9000 points</option>
  21. <option value="10000">10000 points</option>
  22. </select>
  23. <span> minus Value 2 </span>
  24. <select onchange="value2=this.value;Calculate_difference();">
  25. <option value="">Make a selection.</option>
  26. <option value="100">100 points</option>
  27. <option value="200">200 points</option>
  28. <option value="300">300 points</option>
  29. <option value="400">400 points</option>
  30. <option value="500">500 points</option>
  31. <option value="600">600 points</option>
  32. <option value="700">700 points</option>
  33. <option value="800">800 points</option>
  34. <option value="900">900 points</option>
  35. <option value="1000">1000 points</option>
  36. </select>
  37. <div><span>Difference = </span><span id="results"></span></div>
Javascript Code:
  1. <script>
  2. var value1="";
  3. var value2="";
  4. function Calculate_difference()
  5. {
  6.  document.getElementById("results").innerHTML = value1 - value2;
  7.  }
  8. </script>
  9. <span>Value 1 </span>
  10. <select onchange="value1=this.value;Calculate_difference();">
  11. <option value="">Make a selection.</option>
  12. <option value="1000">1000 points</option>
  13. <option value="2000">2000 points</option>
  14. <option value="3000">3000 points</option>
  15. <option value="4000">4000 points</option>
  16. <option value="5000">5000 points</option>
  17. <option value="6000">6000 points</option>
  18. <option value="7000">7000 points</option>
  19. <option value="8000">8000 points</option>
  20. <option value="9000">9000 points</option>
  21. <option value="10000">10000 points</option>
  22. </select>
  23. <span> minus Value 2 </span>
  24. <select onchange="value2=this.value;Calculate_difference();">
  25. <option value="">Make a selection.</option>
  26. <option value="100">100 points</option>
  27. <option value="200">200 points</option>
  28. <option value="300">300 points</option>
  29. <option value="400">400 points</option>
  30. <option value="500">500 points</option>
  31. <option value="600">600 points</option>
  32. <option value="700">700 points</option>
  33. <option value="800">800 points</option>
  34. <option value="900">900 points</option>
  35. <option value="1000">1000 points</option>
  36. </select>
  37. <div><span>Difference = </span><span id="results"></span></div>
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Controlling CSS Question nova912 JavaScript 4 04-26-09 07:45 AM
JavaScript Question pher JavaScript 3 08-30-08 12:17 PM
Javascript question - popup for pictures in IE6/FF1.5.0.8 drewhiggins JavaScript 4 12-01-06 07:16 AM
Question on using Javascript and PHP ajs JavaScript 0 04-20-05 07:11 PM
Huge Javascript question and help... CBRyder13 JavaScript 8 02-11-05 04:54 AM


All times are GMT -5. The time now is 11:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.