Forum Moderators: open

Message Too Old, No Replies

Dynamic form fields updated from child window

         

gnetcon

2:46 pm on Mar 16, 2009 (gmt 0)

10+ Year Member



Hello all!

I have a little problem I'm hoping for the experts to shed some light on.

I have a parent window that has check boxes with various items pulled from a database. When those items are checked on, I need to open a window with a textarea that a user fills in details for each item, one at a time. I have the window opening fine.

The problem is when I go to update the parent window with the content. I have hidden fields for each checkbox that will pass the details. I need to update the hidden field with the data from the child textarea. My main problem is that the fields are passed as the ID of the item from the database, so they may change.

Here's my code:


// open a pop-up window for selected types of support
function displaySupportDetails(data) {
// if the box was checked on, display the pop-up
if (data.checked) {
// set the URL to open
var url = "index.php?v=details&id=" + data.value;

// open the window resized to our form
var detailsWin = window.open(url, "detailsWin", "width=450,height=300,menu=0,scrollbars=0");

// set the opener value
if (detailsWin.opener == null) detailsWin.opener = self;
}
}

// our function to update our parent's window with the details info
function updateParentDetail(num) {
// set our field
var name = "details" + num;
var field = eval("document.details." + name + ".value");
var pfield = eval("opener.document.wo-form." + name);

// if a value was entered, update the parent
if (field != "") {
// update our parent window
alert(field);
//opener.document.wo-form.details1.value = field;
//parent.document.wo-form.name.value = field;
} else {
alert("Please enter the details before submitting the form.");
return false;
}
}

Here's the code in the pop-up window:


<form name="details" id="type-details-form">
<tr>
<td>
Please enter the details of the selected type of support:<br />
<textarea name="details1" cols="50" rows="12" class="input-textarea"></textarea><br />
<input type="button" name="update" value="Submit Details" onclick="updateParentDetail(1)" class="add-button" />
<input type="reset" name="reset" value="Reset" class="add-button" />
<input type="button" name="close" value="Cancel" onclick="window.close();" class="add-button" />
</td>
</tr>
</form>

For the value "updateParentDetail(1)", 1 = the ID from the table that displays the various options.

The parent form is named "wo-form" and the child form is named "details".

Any help would be appreciated! TIA!

gnetcon

9:36 pm on Mar 16, 2009 (gmt 0)

10+ Year Member



Well, I'm happy to say I figured this bugger out on my own. Here's the code I used. Any feedback is still welcome.


// open a pop-up window for selected types of support
function displaySupportDetails(data) {
// if the box was checked on, display the pop-up
if (data.checked) {
// set the URL to open
var url = "index.php?v=details&id=" + data.value;

// open the window resized to our form
var detailsWin = window.open(url, "detailsWin", "width=450,height=300,menu=0,scrollbars=0");

// set the opener value
if (detailsWin.opener == null) detailsWin.opener = self;
} else {
// reset the field to empty
var field = eval("document.srform.details" + name);
field.value = "";
}
}

// our function to update our parent's window with the details info
function updateParentDetail(num) {
// set our field
var name = "details" + num;
var field = eval("document.details." + name + ".value");
var pfield = eval("opener.document.srform." + name);

// if a value was entered, update the parent
if (field != "") {
// update our parent window
pfield.value = field;

// close the window
self.close();
return false;
} else {
alert("Please enter the details before submitting the form.");
return false;
}
}

This opens a new window and, based on the option passed to it, updates the field "details#" on the parent form with the entered text and closes the window.