I am wondering how can I multiply an element value by selecting from <option> tag?

for example I have a <input type='text' value='9'> text tag or <span>9</span> tag and I want to multiply its value by selecting option tag

 <select name="" id="">
     <option value="1/month">1/month</option>
     <option value="2/month">2/month</option>
     <option value="3/month">3/month</option>
     <option value="6/month">6/month</option>
     <option value="12/month">12/month</option>

how to do this?

Votes + Comments
good question
3 Years
Discussion Span
Last Post by ultmt.punisher

Im not too sure I get what you mean as you have left it abit bland, Iv got things to do so ill try answer as best as I can:

  1. Are you using JavaScript or another scripting language?
  2. Do you want to multiply the value 9 by the value of the option selected?

If my guess is right ill take a stab at it.

First off you must give your <select> and id, lets give it <select id = 'mySelect'>. Its is handy to note that options in a select are stored in an array with the first element (option) starting at 0, using this index is how we can access each element in our script to do the multiplication.

Now to the function that does the multiplication:
1. Assign your select and text input to a variable and one for the selected option:

var mySelect = document.getElementById('mySelect');
var myTextInput = document.getElementById('myTextInput');
var selectValue = mySelect.options[mySelect.selectedIndex].value;
  1. Use mySelect variable to access any of the elements
  2. multiply selectValue by myTextInput.Value

Im guess youd have an idea on how to do the last part yourself. You could use a for loop.


I still dont understand it, and yes ofcours I am using javascript.

can you please more elaborate it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.