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 2 of 2

Thread: calculate

  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calculate

    here is my code..what i want to do is..depenting from what the user presses from the 3 choices in the form..i want to have a different variable to calculate..ih the user presses the first option then the variable would be -->1
    else if presses second option variable --> 2 else variable-->3

    Code:
    
    <script>
    
    function foros()
    {
    var one= document.getElementById ('smth').value;
      
    
         {
          missing code  help me ;)
         }
    
    
    	var result=0.15*variable
            document.write('taxis is: ',result)
    </script>
    
    
    select id="smth" name="Smth"  >
        <option  value="0" selected="selected" > no </option> 
        <option  value="1" >yes</option>
        <option  value="2" >maybe</option>
    </select>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    You are reading the string(!) value of the selected option into the variable "one" already. All you need to do is to convert it to an integer
    Code:
    var one = document.getElementById('smth').value;
    var variable = Number(one);
    var result = 0.15*variable;


  •  

    Posting Permissions

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