Copying selected index, copying data from one to other placeCopying user entered data from one area to the other is required to help the user as they need not enter the same data again. For example if we are asking the user to enter home and office address and for a user if both are same then the user can click a button or period button saying Same As Above . They need not enter the data again. This we have discussed in the tutorial on how to copy form field data from on place to other. Now we will try the same example with a drop down list box included. To our pervious tutorial we will add some changes and we will make the state list a drop down with some few ( example ) data inside it. From this state list what ever is selected as state by the user in the first group will be copied along with the other text field data to the second group and the same state in the state list in second group will be selected.
Once the period button is clicked (or this can be associated with any other event) then first we have to find out which item is selected from the list box one (that is state list) by looping through all the elements of the list box and checking them. For this we will use the length property of the list box and assign its value to the for loop. The loop will pass through each element of the first list box. We will use one if condition inside the for loop to check which of the option is selected. Once we found the option selected we will make the corresponding option of the second groups list box selected. We will be using the index value for the options so both the list box should maintain the same order for the options. Here is the code for this part.
ListBox Validation : Checking if option is selected before submitting a form
ListBox Disable: using disabled property we can disable a listbox by radio button
Adding option: Adding options to a listbox dynamically
Moving Options Moving Options from a listbox to other
Removing Options: Removing options from a listbox
Copying List data : Copying user entered data from one to other form
Dependant list box : Linking two dropdown listboxes
list box with Data : Populating Listbox by taking data from MySQL table
Listbox Menu: Redirecting page based on selection of listbox