-1

How would I get the index of the selected Mobiscroll Item? I am using the 'select' option. onClose calls function(valueText, btn, inst) and onChange calls function(valueText, inst). I can get the 'display' text, button, inst, etc., but not the index of the selected item.

On the Scroller I am displaying the file names in a formatted manner. I need to use the index to get the correct filename from an array. How do I get the index? :-)

Any suggestions?

Thanks a ton. M&M

None
  • 5,491
  • 1
  • 40
  • 51
R.W
  • 530
  • 1
  • 12
  • 34
  • Can you post the relevant code? It is better to include the relevant code in code blocks than trying to describe it in words. – None Apr 11 '14 at 17:09
  • Well I could use one of these Mobiscroll functions: onSelect : function(valueText, inst) OR onChange:function(valueText, inst) OR onClose: function(valueText, btn, inst) But how do I get the "index" of the selected item rather than the text? This is because my display text is different from actual value of the item. – R.W Apr 12 '14 at 01:56
  • Ok I found an easy way out. When I am adding items to Mobiscroll, I also populate an array with the same values. Then all I need to do is "var selected_index = myArray.indexOf(valueText);" and I can get the index of the selected item. The first item index will be a 0. And I can use this in both onClose as well as onSelect events of Mobiscroll. Thanks a ton anyways guys! – R.W Apr 12 '14 at 07:32
  • You should post that as an answer. – None Apr 13 '14 at 20:00
  • Ok sure thanks...I am a newbie to SO. – R.W Apr 17 '14 at 08:05

1 Answers1

2

Ok I found an easy way out. When I am adding items to Mobiscroll, I also populate an array with the same values. Then all I need to do is "var selected_index = myArray.indexOf(valueText);" and I can get the index of the selected item. The first item index will be a 0. And I can use this in both onClose as well as onSelect events of Mobiscroll. Thanks a ton anyways guys!

R.W
  • 530
  • 1
  • 12
  • 34