I've done my best scouring the Net for answers to this one, and I can't seem to find anything. Here's the task:
I'm building an admin application that will allow users to view and update database records. The parent page displays a single record from the "news" database. I've created a button that launches a popup window which displays all records in the "images" database. Each record has its own button which closes the popup, assigns the appropriate record ID number to a variable, and passes the variable back to a text field on the parent page. That's where the trouble starts.
In order for the javascript function to pass the variable, it needs to know the name of the text field. PHP, of course, wants to include the correct database coding so that it knows where to post the updated information. When I enter the name of the text field, complete with its PHP glory, into the javascript, Java wants nothing to do with it. The script fails to function. If I eliminate the PHP coding from the field name the script works perfectly. The downside is that the field can't be updated.
I've posted pared-down versions of the code in both pages below (in this state, the script functions but I cannot update the record). My solution may be fundamentally flawed, or there may be a simple answer. Any input is appreciated. Many thanks!
PARENT PAGE
<script>
var dialogArguments;
function getValue (field) {
dialogArguments = field;
open ('browse.php', 'popup',
'width=400,height=400,scrollbars=1');
}
</script>
<body>
<p>Image ID:<br>
<input type="text" name='aText' value='<?php echo fixHTMLquotes($news->Value("news_image")) ?>' size="5">
<input onclick="getValue(this.form.aText)" type="button" name='' value="Browse Images" >
</body>
POPUP PAGE (browse.php)
<form name="aForm">
<p><input type="button" name="gods" value="Select This Image" onclick="window.opener.dialogArguments.value = <?php echo $images->Value("image_id")?>; window.close()">