Solved

Accessing previous value in a combo box

Posted on 2004-03-26
8
138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

622 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