Connecting Tech Pros Worldwide Help | Site Map

re-populate combobox

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 16th, 2007, 07:25 AM
Bob Bedford
Guest
 
Posts: n/a
Default re-populate combobox

Hi all,

I've a code in wich I do fill 2 comboboxes.

By selecting a value in the first one, the options change in the second one.
Now when I click on "back" button of IE, the values are lost. I mean I've
the value in the first combo, but the second one is empty.
I do save the values in a session variable (my site is in PHP), so I know
wich values have been selected. So my question is:
how to select the values again ?

In the example below, when you submit, the values are passed by GET (seen on
URL). Clicking "back" button, the selected value in combo1 is selected
again, but the combo2 is empty.
I've to select a new value and select the desired value again to get it
filled.

Here is the code (filename testjs.html):

<html>
<body>
<form name="FormSubmit" action="testjs.html">
<select NAME="SELECT1" ID="SELECT1"
onChange="subselect(this.options.selectedIndex)" ="combobox">
<option value="" selected>all</option>
<OPTION VALUE="1">option1</OPTION>
<OPTION VALUE="2">option2</OPTION>
</select>
<select NAME="SELECT2" ID="SELECT2" class="combobox">
<option value="" selected>all</option>
</select>
<input type="submit" name="submit">

<script>
<!--
var groups=document.FormSubmit.SELECT1.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][1]=new Option("option1")
group[0][2]=new Option("option2")

group[1][0]=new Option("all ")
group[1][1]=new Option("sub1-1","1")
group[1][2]=new Option("sub1-2","2")
group[2][0]=new Option("- all - ")
group[2][1]=new Option("sub2-1","3")
group[2][2]=new Option("sub2-2","4")

var temp=document.FormSubmit.SELECT2

function subselect(x){
for (i=temp.options.length-1;i>0;i--)
temp.options[i]=null
for (k=0;k<group[x].length;k++){
temp.options[k]=new Option(group[x][k].text,group[x][k].value)
}
temp.options[0].selected=true
}
//-->
</script>
</form>
</body>
</html>

Thanks for helping.

Bob



 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.