Click to See Complete Forum and Search --> : What Am I Missing???


rjusa
11-19-2003, 08:40 AM
Here's what I've got that works:

a parent form 'forms[0]' that opens a child '<form name="childForm">'...

in the child a drop down box that allows for multiple selections...'<select name="select1" size="5" multiple>
<option name="option1" value="Alabama">Alabama</option>
<option name="option2" value="Alaska">Alaska</option>
.
.

</select>'

a script routine that takes the selections from the drop down and assigns them to a new name 'function States5Year() {
if (document.childForm.select1.options[0].selected)
document.childForm.state1.value=document.childForm.select1.options[0].value;

if (document.childForm.select1.options[1].selected)
document.childForm.state2.value=document.childForm.select1.options[1].value;
.
.
}
</script>'

a 5x1 table with text boxes to check if the selections are being assigned correctly '<input type=textbox size="16" name="state1" value="">'
.
.
Ok, so I make my selections and click a button '<input type="button" value="States" name="States5" onClick="States5Year()">' and sure enough the selections now appear in the text boxes so I'm assuming that the value(s) state1, etc DO EXIST!

Sooo, I want to pass these values back to parent 'function updateParent(childForm) {

opener.document.forms[0].state1.value = document.childForm.state1.value;
opener.document.forms[0].state2.value = document.childForm.state2.value;
.
.
self.close();
return false;
}

Well, when I click the button <form name="childForm" onSubmit="return updateParent(this);"> the selections in the drop down are cleared, the text boxes are cleared, nothing is tranfered over to the parent and I'm still in the child! Where did I screw up? This is driving me nuts.

Oh yeah, if I take out the drop down and just type in the states in the child text boxes, the values get passed to the parent and the child closes! I must be close! (Maybe?)

Thanks,
Ron

gil davis
11-19-2003, 04:40 PM
I wish you would keep one thread going rather than starting a new one each time you get a little farther... ;)

I read posts from the top of the list (newest first) down, so I read and answered your most recent post. That leads me to believe that you apparently got past this particular problem.

rjusa
11-19-2003, 06:07 PM
Gil -

I apologize for not continuing the same thread and will make a concerted effort in the future to do so. Thanks. Your suggestion for shortening my lengthy code didn't seem to work. I don't think I missed anything:

<body>
<script language="JavaScript"><!--

function update() {
var output = new Array("","","","","","",""); //0-6
for (var i=0; i<7; i++)
{if (document.forms[0].selectfield.options[i].selected)
{output[i] += document.forms[0].selectfield.options[i].text + ' ';}
opener.document.forms[0]["resultfield" + i + 1].value = output[i];
}
window.close();
}
//--></script>

<form onSubmit="return false">
<select multiple name="selectfield">
<option>Monday
<option>Tuesday
<option>Wednesday
<option>Thursday
<option>Friday
<option>Saturday
<option>Sunday
</select>
<p>
<input type="button" value="Update" onClick="update()">
</form>
</body>

Thanks again,
Ron

gil davis
11-19-2003, 07:05 PM
It would help to see the opener.

rjusa
11-19-2003, 07:07 PM
opener code:

<script language="JavaScript"><!--
function myopen() {
popupWindow=open('TestMchild.html','windowName','resizable=no,width=400,height=300');
if (popupWindow.opener == null) popupWindow.opener = self;
}
//--></script>

<form>
<input type="text" size="40" name="resultfield1"><br>
<input type="text" size="40" name="resultfield2"><br>
<input type="text" size="40" name="resultfield3"><br>
<input type="text" size="40" name="resultfield4"><br>
<input type="text" size="40" name="resultfield5"><br>
<input type="text" size="40" name="resultfield6"><br>
<input type="text" size="40" name="resultfield7"><br>
<input type="button" value="Open" onClick="myopen()">
</form>
</body>

gil davis
11-19-2003, 07:12 PM
Sorry, I found it. Change
opener.document.forms[0]["resultfield" + i + 1].value = output[i];to
opener.document.forms[0]["resultfield" + (i + 1)].value = output[i];

rjusa
11-19-2003, 07:37 PM
Gil -

Awesome! Thanks for all the help. Works like a charm both in Netscape and IE.

Do you know of any references I could go to for the next step...trying to code the text boxes in the parent gray (or some color) that aren't filled in with the selections from the child ??

Thanks again,

Ron

gil davis
11-19-2003, 08:07 PM
Not really. Just the specs.

http://www.w3.org/
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp
http://devedge.netscape.com/central/javascript/

CSS would be the way to go.
<form>
<input type="text" style="background-color: lightgrey">
</form>
You can script it using
document.formName.textboxname.style.backgroundColor = "lightgrey";