Solved

Accessing previous value in a combo box

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
From XSL to Word - How add a page break? 5 29
jquery validation by class 12 52
What language/protocol is the Angular Chat? 2 58
How to write an English digest paper 6 25
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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 …

863 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

22 Experts available now in Live!

Get 1:1 Help Now