Click to See Complete Forum and Search --> : Passing Values


mrdxw15
03-15-2003, 01:17 PM
Hi, can anyone help before I pull out all my hair.

I have 2 forms. On the first form I have an empty multiple select. Users make choices in other fields on the same form and these are used to populate the multiple select. The additions are made to the multiple select by 'new option'.

When the user has finished I want to pass all the text and values from the multiple select to the second form. The data is to populate an empty multiple select on the second form.

Any help would be appreciated.

Thanks

khalidali63
03-15-2003, 01:50 PM
typically

document.formName.elementName.value = document.formName.elementName.value

will put a value to another form field.

for selection boxes.

var listBox1 = document.formName1.listboxName1;

var listBox2 = document.formName2.listboxName2;

listBox2 .length = listBox1.length;

go through listbox1 in the frst form and get values to put the second one

for(x=0;x<listBox1.length;x++)[
listBox2.text = listBox1[x].text;
listBox2.value= listBox1[x].value;
}

The above will copy the exact values in the firsr list box to the second forms listbox.

If you want only selected values to apear in the second list box then

var value = listBox1.options[listBox1.selectedIndex].value;

and then you can put it in the second list box just as in the loop above.

Hope this helps

Cheers

Khalid

mrdxw15
03-15-2003, 04:54 PM
Thank you Khalid for taking the time to look into my problem.

I would like to take things a little further though. I need to pass the data from input.html to output.html. Both forms start with empty multiple select fields. The first is populated using the code below.

function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
var optionName = new Option(text, value, defaultSelected, selected)
object.options[object.length] = optionName;
}

function copyAll(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
}

The problem I have is mainly trying to pick up the information in the second file and populating the multiple select. If you have a few minutes to help it would be appreciated. Thank you.

khalidali63
03-15-2003, 05:18 PM
Ok.here is the link.It displayes one way of passing values from a page to another and on the other oage it has the functionality to parse the URL and show how to display the data appropriately.

http://68.145.35.86/skills/javascripts/DemoForwardFormDataViaURL.html

In conjunction with your existing code you can easily do what you want.

Cheers

Khalid

mrdxw15
03-15-2003, 05:47 PM
Thank you Khalid. I tried your code and it did work but I need to use multiple select fields.

Best wishes

Dave Wright

mrdxw15
03-15-2003, 06:01 PM
Khalid, if its any help I have made a temporary addition to my site so that you can see what I'm doing. The site is www. uksearchindex.com . On the left hand side you will see an entry for pins. This is form I'm working on.

Best wishes

Dave Wright