0

My code has a variable that contains the multiple value something like: var GlobalOpportunityTypeID="8|9|10"

I want to split this value into different variables as per my requirement. How can I do this? Can anyone please let me know?

Shiridish
  • 4,942
  • 5
  • 33
  • 64
amit Verma
  • 27
  • 2
  • Use can use regular expressions. I what way you want to split. Show a example so that the solution can be suggested well – Shiridish Sep 05 '12 at 08:46
  • suppose i have webpage1 and webpage2.when i select multiple dropdown combox box,one after another and click on search to find something.it will show some data in datagrid.when i click on any particular data.it shows detail view of that.I wanted that when i click back button on detailed page.it should show the same dropdown selectedID which was before at the time of search,instead of showing byDefault Select. – amit Verma Sep 05 '12 at 08:53
  • tht's why i use one variable to store the ID of dropdown's and that what i want to split in different variable.Please let me know? – amit Verma Sep 05 '12 at 08:54
  • What I understand is that you want to store the values of those selected in the combo boxes even after you navigate to the next page. Am I right? – Shiridish Sep 05 '12 at 09:00

1 Answers1

1

Use split() to split the values into an array, then unpack the array into variables.

var ids = GlobalOpportunityTypeID.split("|");
var id0 = ids[0],
    id1 = ids[1],
    id2 = ids[2];

If the number of variables is unknown or dynamic, then you might be better off dealing with the the array itself and not extract them to individual variables.

Community
  • 1
  • 1
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
  • the first dropdown now contains the value after i get back to previous page as same which i had before moving to second page..but the variable use only the value of first dropdown..the other dropdown still have their ID as 'SELECT'..i want it to as before..what i had selected. – amit Verma Sep 05 '12 at 12:00
  • I'm afraid I don't understand your comments. To me, it does not sound at all related to the question as you have posted. Perhaps you should considered adding more details into your question or even ask a different question. Right now, all your question asks is how to split a string to separate variables. – Shawn Chin Sep 05 '12 at 12:44
  • Dont bother now..it's quite complex requirement in my project.what i need is that after selecting the filters(more than 1) in one page,when we search for the result,some list will appear,after clicking on any list the detail will be display.Then,if i want to get back to the previous page,i want the same grid and value in dropdown which i used for searching. – amit Verma Sep 05 '12 at 13:02
  • ?... OK, I won't bother. Good luck with your project. – Shawn Chin Sep 05 '12 at 13:30