Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

howto populate a select box using post data from a previous select box

Status
Not open for further replies.

simonTheTraveller

Programmer
Jun 29, 2006
16
0
0
GB
Hi all. What I'm trying to do is get the contents of a select control from a previous pages form and then populate a new select control using all the options in the previous one (using jsp)

Its for a life insurance calculator. The user puts in details of all previous eplans they have in place. There may be more than one plan so they have the option to keep adding plans. Once this is done, they proceed to a summary page which display everything including all the existing plans.

What I want to know is how can I access all the options in a particular select control to output them? I've already set all the options to selected in the previous form. Is this what I need to do or is there some other way?

If I'm going about this the wrong way, can you suggest an alternative? Many thanks.
 
Code:
<html>
<head>
<script lang="JavaScript">
var count = 0;
function mystore(inpname){
var str = "document.f1."+inpname;
obj = eval(str);
if (obj.selectedIndex!=0)
   {
    if (count>0)
       {
        document.f1.secret.value+="_"
       }
    document.f1.secret.value+=obj[obj.selectedIndex].value;
    count++;
   }
}
function showAll()
 {
  alert(document.f1.secret.value);
 }
</script>
</head>
<body>
<form name="f1">
<input type="hidden" name="secret" value="">
<select name="sa">
<option value="">choice sa</option>
<option value="a001">plan a001</option>
<option value="a003">plan a003</option>
</select>
<input type="button" value="add to list" onClick="mystore('sa')">
<br>
<select name="sb">
<option value="">choice sb</option>
<option value="b002">plan b002</option>
<option value="b004">plan b004</option>
</select>
<input type="button" value="add to list" onClick="mystore('sb')">
<br>
<select name="sc">
<option value="">choice sc</option>
<option value="c001">plan c001</option>
<option value="c005">plan c005</option>
</select>
<input type="button" value="add to list" onClick="mystore('sc')">
<br>
<input type="button" value="submit form" onClick="showAll()">
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top