Solved

Accessing previous value in a combo box

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

752 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