Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Accessing previous value in a combo box

Posted on 2004-03-26
8
Medium Priority
?
141 Views
Last Modified: 2010-04-06
Hi All,
I have a case where I have about 4-5 combo boxes which have several values in each combo box. Now, I also have the condition that the item that you select in one combo box should not be the same as any one of the selections that you make in another combo box.
Eg: If you select "India" in one combo box, you cannot select "India" again in any of the other combo boxes.
Now, suppose I select "India" in one of the combo boxes. And, now in the second combo box I select "Australia". Now, again I try to select "India" in the second combo box again. This will invoke a Javascript function which will give me a message box saying it cannot be same as the first selection. This can be done. But, after this message is shown, how could you get back "Australia" that you selected "PREVIOUSLY" back into combo box 2?
Any help is appreciated.
Thanks in Advance,
Divya.
0
Comment
Question by:disridha
8 Comments
 
LVL 2

Expert Comment

by:aabbas
ID: 10686609
It seems that you will need to have variables to store previous values of each combo box, because you will need the same functionality for every combo box.

Now, the flow will be like:

1. When a value is selected in a combo box, check whether the same is selected in others.
2. If selected a unique value, store this value in the variable for this particular variable.
3. If selected a value that is already selected in others, assign variable's value to combo box, so that previous value is re-selected.

You may also use an array instead of having variables for each combo box, and use array index.

Hope, it will help.

Best of luck.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10686739
you can use hidden fields.

Btw, what language are you using?
0
 
LVL 4

Expert Comment

by:llcooljayce
ID: 10692259
<input type = "hidden" value = "name of combo box from the first iteration">
This will pass on the value to the next time the form is submitted.
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 10695984
Like this:

<html>
<head>
<title> Last Selected </title>
<script type="text/javascript">
<!--
var selpntr = new Array(0,0,0,0,0);
function testIt(idx,pntr)
{
    frm=document.forms['theform'];
    thesel='select'+pntr;
    EL=frm.elements[thesel];
    for (i=0;i<selpntr.length;i++)
    {
       target='select'+i;
       targetsel=frm.elements[target];
       if (EL!=targetsel && idx==selpntr[i])
       {
          alert('you cannot make the same selection');
          EL.selectedIndex=selpntr[pntr];
          return;
       }
    }
    selpntr[pntr]=idx;
}
//-->
</script>
</head>
<body>
<form name="theform">
<select name="select0" onchange="testIt(this.selectedIndex,0)">
<option value=" ">
<option value="India"> India
<option value="Australia"> Australia
<option value="Indonesia"> Indosnesia
<option value="Japan"> Japan
<option value="China"> China
</select>
<select name="select1" onchange="testIt(this.selectedIndex,1)">
<option value=" ">
<option value="India"> India
<option value="Australia"> Australia
<option value="Indonesia"> Indosnesia
<option value="Japan"> Japan
<option value="China"> China
</select>
<select name="select2" onchange="testIt(this.selectedIndex,2)">
<option value=" ">
<option value="India"> India
<option value="Australia"> Australia
<option value="Indonesia"> Indosnesia
<option value="Japan"> Japan
<option value="China"> China
</select>
<select name="select3" onchange="testIt(this.selectedIndex,3)">
<option value=" ">
<option value="India"> India
<option value="Australia"> Australia
<option value="Indonesia"> Indosnesia
<option value="Japan"> Japan
<option value="China"> China
</select>
<select name="select4" onchange="testIt(this.selectedIndex,4)">
<option value=" ">
<option value="India"> India
<option value="Australia"> Australia
<option value="Indonesia"> Indosnesia
<option value="Japan"> Japan
<option value="China"> China
</select>
</form>
</body>
</html>

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12554707
I answer the question with full code IMHO.

Cd&
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question