Focal Point
JavaScript to divide one variable into two

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5961018331

December 06, 2004, 11:07 AM
CHERI
JavaScript to divide one variable into two
Good Morning:
I have a html page that I'm allowing multiple selections from a drop down list box. The variable I'm passing to the focus program consists of two fields concatenated together. With Javascript I would like to break this variable into two seperate variables. I know I accomplish this within the focus program but I would like to use Javascript. Has anyone done this before ?
December 06, 2004, 11:21 AM
Håkan
Given you have a separator, you can use the method split:

arrayOfStrings = stringToSplit.split(separator);

H�kan
December 06, 2004, 11:37 AM
CHERI
I think the problem I'm having is it is not recognizing the value in the select list box. Any thoughts ?
December 06, 2004, 11:54 AM
Håkan
This is what I've used:

var x = document.adj.ACTION.selectedIndex;
var opt = document.adj.ACTION.options[x].value;

Now you can perform your split on the var opt.

H�kan
December 06, 2004, 12:10 PM
CHERI
If I use an alert and display the value of 'x' I do see the number representing the item selected. However, if I use an alert to display the value of 'opt' I do not see a value. I should be, correct ?
December 06, 2004, 02:08 PM
TexasStingray
CHERI

FYI besure that the option does have an actual value= in it. Otherwise you will have to use the text.