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
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help Converting a physical string to a integer

    Hi all,

    I am having a problem converting a physical string to a integer. I have a dropdown list of a few items but are numbers though in chracters. I ned to output the value and the text of the selected item. As I cannot use a if-else statement, any help would be great.

    Code:
    <select id="std_num" onchange="displayValue()">
                	<option value="Two">Two</option>
                    <option value="Zero">Zero</option>
                    <option value="Five">Five</option>
                    <option value="Three">Three</option>
                    <option value="Two">Two</option>
                    <option value="Zero">Zero</option>
                 </select>
    Code:
    function displayValue()
    {
    	alert(document.getElementById('std_num').value);
    	var c = (document.getElementById('std_num').value);
    }

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    Code:
    function displayValue()
    {
    	alert(document.getElementById('std_num').value);
    	var c = (document.getElementById('std_num').value);
            // you can add more values in this map as required
    	var map = {'zero':0,'one':1,'two':2,'three':3,'four':4,'five':5}; 
    	alert(map[c.toLowerCase()]);
    
    }
    Thanks & Regards,
    Niral Soni


  •  

    Posting Permissions

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