Solved

Accessing previous value in a combo box

Posted on 2004-03-26
8
133 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 125 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now