Code:
<html>
<head>
<style>
div.formfield {border: 1px solid #000000}
</style>
</head>
<body>
<script language='JavaScript' type='text/javascript'>
var child;
function form_child()
{
child = window.open('', 'child_win', 'width=550,height=100');
child.document.open();
child.document.write("<form name='dest'>");
child.document.write("<select name='test' size='3' multiple='multiple'>");
child.document.write("<option value='value1'>value1</option>");
child.document.write("<option value='value2'>value2</option>");
child.document.write("</select>");
child.document.write("<input type='submit' name='do_action' value='Post' />");
child.document.write("</form>");
child.document.close();
var n;
var index;
var new_option;
var text_element = document.source['test'].value;
var select_element = child.document.dest['test'];
var values = text_element.split(',');
for (n = 0; n < values.length; n++)
{
if (false !== (index = in_options(values[n], select_element)))
{
select_element.options[index].selected = true;
}
else
{
new_option = select_element.length + 1;
select_element.options[new_option] = new Option(values[n], values[n], false, true);
}
}
}
function in_options(search, select_element)
{
var i;
for(i = 0; i < select_element.length; i++)
{
if (search == select_element.options[i].value)
{
return i;
}
}
return false;
}
</script>
<form name='source'>
<div class='formfield'>
<div class='formdescription2'>
<div class='formtext'>
<a href='javascript:void(0);' onclick='form_child()'>Move value:</a>
</div>
</div>
<div class='forminput2' id='mail_composerfield6'>
<input type='text' name='test' value='value1' size='50' />
</div>
</div>
</form>
</body>
</html>
Basically my problem goes like this.. I have a text element in the opened window. Once the 'Move Value' link in clicked an event handler fires and the data is to get transferred to a <select> element in the child window that opens. The data then gets exploded into an array via the split method. If the data is already in the select menu then it is to be merely selected, if not then a new option should be added.
The problem I am experiencing is when I run the code in IE the browser crashes when it gets to the line:
select_element.options[new_option] = new Option(values[n], values[n], false, true);
And in Mozilla it does nothing but highlight the existing elements as selected but does not add new options.
The application for this is I am wanting to open up an address book into the child window where a user can highlight email addresses and then those addresses are passed back to the parent window. If addresses appear in the text field that aren't in the address book supplied by the database they just get appended to the bottom of the select field.
I hope all that makes sense!
Any help gratefully received!
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::