Simple Java Code Needed
I’m trying to build a form where when you click a button a new window opens. There we choose an item and send the item code back to the parent page to populate a text field. After this is done the new window should close automatically. This is the code I’m working with at the moment. I think the head of the child file needs changing.
parent file (parts of it):
Code:
//head:
<script type=”text/javascript”>
targetElement = null;
function addProduct(frm, id) {
if(!frm || !id)
return;
targetElement = frm.elements[id];
var handle = window.open(‘find_product.php’);
}
</script>
//body:
<form id=”frm” name=”frm” action=”#”>
<input name=”code” type=”text” id=”code” size=”10″ />
<input name=”name” type=”text” id=”name” size=”32″ />
<input type=”button” value=”Add Item” onclick=”addProduct(this.form, ‘code’);” />
</form>
child file (parts of it):
Code:
//head:
<script type=”text/javascript”>
function addProduct(frm, id) {
if(!frm || !id)
return;
var elem = frm.elements[id];
if(!elem)
return;
var val = elem.options[elem.selectedIndex].value;
opener.targetElement.value = val;
this.close();
}
</script>
//body:
<form id=”frm” name=”frm” action=”#”>
<input name=”code” type=”hidden” value=”<?php echo $row_rsProducts['ProductID']; ?>” />
<input name=”name” type=”hidden” value=”<?php echo $row_rsProducts['ProductName']; ?>” />
<input type=”button” value=”Add Product” onclick=”addProduct(this.form, ‘code’);” />
</form>
Another thing that I’m not sure how to go round is that forms can’t be nested so after the field is filled in, how can I submit the value? I’d like to use this same field for another form.
Please bid only if you can solve both of these problems.


