soquinn
06-10-2003, 07:02 PM
Hello folks, I’m not familiar with editing JavaScript code and was wondering if anyone can help? I’m trying to populate a text field in a form with values from a popup or DHTML window. Similar to a popup calendar selection function.
The text field reference I want populated from a popup list of items looks like this:
<input type=text name=b[optional_field_1] id=optional_field_1 value="">
I can't seem to reference the "name=" in the javascript because it has [] in it. So I tried to reference the id.
I call the popup window with:
<a href="#" onClick="window.open('http://mysite.com/popup-file.php','popuppage','width=550,height=500,top=20,left=100,scrollbars=1,resizable=1,toolbar=1,locat ion=1,menubar=1');">Select Make</a>
and use this to send the selected value back to the text field:
<SCRIPT LANGUAGE="JavaScript">
function populate_parent_formfield(val)
{
alert("val: " + val)//make sure that it is what you chose in the pop-up window select box; remove once verified
var elarray = window.opener.document.classified_details_form.elements;
for(var i = 0; i < elarray.length; i++)
{
if(elarray[i].id == "optional_field_1")
{elarray[i].value = val; break;}
}
}
</script>
this is the popup window button to send back the value:
<input type=button value="Add Make" onClick="populate_parent_formfield(document.selectform.elements['selectmenu'].selectedIndex.value)" name="button">
This is as far as I could get with help from others. Any suggestions on what might be missing would be greatly appreciated. Can id’s be referenced or is there another/better way to send the value back to the text field?
Thanks in advance,
Shawn
The text field reference I want populated from a popup list of items looks like this:
<input type=text name=b[optional_field_1] id=optional_field_1 value="">
I can't seem to reference the "name=" in the javascript because it has [] in it. So I tried to reference the id.
I call the popup window with:
<a href="#" onClick="window.open('http://mysite.com/popup-file.php','popuppage','width=550,height=500,top=20,left=100,scrollbars=1,resizable=1,toolbar=1,locat ion=1,menubar=1');">Select Make</a>
and use this to send the selected value back to the text field:
<SCRIPT LANGUAGE="JavaScript">
function populate_parent_formfield(val)
{
alert("val: " + val)//make sure that it is what you chose in the pop-up window select box; remove once verified
var elarray = window.opener.document.classified_details_form.elements;
for(var i = 0; i < elarray.length; i++)
{
if(elarray[i].id == "optional_field_1")
{elarray[i].value = val; break;}
}
}
</script>
this is the popup window button to send back the value:
<input type=button value="Add Make" onClick="populate_parent_formfield(document.selectform.elements['selectmenu'].selectedIndex.value)" name="button">
This is as far as I could get with help from others. Any suggestions on what might be missing would be greatly appreciated. Can id’s be referenced or is there another/better way to send the value back to the text field?
Thanks in advance,
Shawn