...

View Full Version : Re: Help Converting a physical string to a integer



putha
10-13-2011, 03:08 PM
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.


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


function displayValue()
{
alert(document.getElementById('std_num').value);
var c = (document.getElementById('std_num').value);
}

niralsoni
10-13-2011, 05:02 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum