Set Text in form field from pop up window

T

Tim Pollard

Hi

I'm not much of a javascripter, so I don't know whether this is
possible, but......

I have a pop-up window in my asp web app which lets the user select a
record from table1 from an alphabetical list - you know, the A | B | C
| D filter thang.

At the moment they have to cut and paste the appropriate recordID into
a text box on the parent form, which is editing data from table2 (ie.
this process is linking the two tables).

I know I can use javascript to set the text in a box on a form if I
check a box elsewhere on the same form. Question is, can I set the
text in the parent form when I check a box on the pop-up?

Any pointers very gratefully received!

Thanks
 
M

Martin Honnen

Tim Pollard wrote:

I know I can use javascript to set the text in a box on a form if I
check a box elsewhere on the same form. Question is, can I set the
text in the parent form when I check a box on the pop-up?

You can access the opening window as follows
if (opener && !opener.closed) {
opener.document.formName.elements.elementName.value = ...;
}
 
T

Tim Pollard

Hi

For the benefit of anyone following this thread later, here's how I
solved it by using the help above and applying it to the way
Dreamweaver does things:

Step 1

Called the popup from a # link on the master page, onClick the link
calls function openwin() .

Function openwin looks like this in code view:

function openwin() {
aff = window.open('','NewWin',
'toolbar=no,status=no,scrollbars=1,resizable=1,width=630,height=700,left=100,top=100')
aff.location="TownPicker.asp";
}

Townpicker.asp is my pop up page.

Step 2

Made sure my pop up repeat region was inside a form tag.

Put a radiobutton in my repeat region and assigned the dynamic ID to
it as its value.

Created a text field and applied the Set Text behaviour onClick to the
radiobutton, setting the dynamic ID as the value to write to the text
box. e.g. set it to write <%=(rsTowns.Fields.Item("TownID").Value)%>

Check this is all working when the radiobuttons are clicked - check
the text changes from button to button.

Step 3

Find the script for the macromedia MM_setTextOfTextfield function and
add this line to the end of the function:
opener.document.form1.elements.SCoTownID.value = newText;
where form1 is the name of the form on the parent page and SCoTownID
is the name of the field on it you want to populate.

Thus the modified code for the set text function is:

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
var obj = MM_findObj(objName); if (obj) obj.value = newText;
opener.document.form1.elements.SCoTownID.value = newText;
}

What this does is take the value the MM function has generated
(newText) and pushed it back to the field in the opening page.

Once this is all working properly you can hide the text field in the
popup and it should now all work fine.

Many thanks for the suggestion that solved this problem for me!

TP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top