Jump to content

[SOLVED] fill a form field from a different window


interpim

Recommended Posts

Hello all, I want to start with the fact I have Very Little knowledge of javascript but am willing to learn.

 

What I am trying to do I think requires javascript, but I don't know how to implement it.

 

Basically, I have a phpbb that I run.  I am trying to create a plug-in that will allow my forum users to click a link when they are writing a post that when clicked will pull up a pop-up window.  The pop-up will process an upload of an image via PHP, but the thing I want it to do is when that form is submitted, I want the image path/name of the uploaded image to be put into the forum text field with the bbcode tags around it automatically.  This is to basically make picture posting dummy proof for my users.

 

Any recommendations are appreciated.

Link to comment
Share on other sites

page1.html

<SCRIPT LANGUAGE="JavaScript">
<!--
function openChild(file,window) {
    childWindow=open(file,window,'resizable=no,width=200,height=400');
    if (childWindow.opener == null) childWindow.opener = self;
    }
//-->
</SCRIPT>
<FORM NAME="parentForm">
<INPUT TYPE="button" VALUE="Open child" onClick="openChild
('page2.html','win2')">
<BR><INPUT NAME="pf1" TYPE="TEXT" VALUE="">
<BR><INPUT NAME="pf2" TYPE="TEXT" VALUE="">
</FORM>

 

page2.html

<SCRIPT LANGUAGE="JavaScript">
<!--
function updateParent() {
    opener.document.parentForm.pf1.value = document.childForm.cf1.value;
    opener.document.parentForm.pf2.value = document.childForm.cf2.value;
    self.close();
    return false;
}
//-->
</SCRIPT>
<FORM NAME="childForm" onSubmit="return updateParent();">
<BR><INPUT NAME="cf1" TYPE="TEXT" VALUE="">
<BR><INPUT NAME="cf2" TYPE="TEXT" VALUE="">
<BR><INPUT TYPE="SUBMIT" VALUE="Update parent">
</FORM>

 

Works Like A Charm Just Try It Out

An Example Is Also Available: Here

Link to comment
Share on other sites

Ok... that does work... but, it also erases anything that exists in the form already.

 

What i want to do is leave any text the user has typed still in the box, but add the link which I will create with PHP inside bbcode for images.  For instance... I'm typing a reply on a forum.  I want to add a picture.  I click the link at the bottom of the form, it opens a popup with an upload dialog.  The user searches for the image, clicks upload, and once the upload is complete.  The path to the image is returned to the original form where the users cursor was when they were typing.  Leaving everything that they had typed out already.

 

Is this possible with Javascript?  Or do I have to pass that text somehow?

Link to comment
Share on other sites

Page 1

<SCRIPT LANGUAGE="JavaScript">
<!--
function openChild(file,window) {
    childWindow=open(file,window,'resizable=no,width=200,height=400');
    if (childWindow.opener == null) childWindow.opener = self;
    }
//-->
</SCRIPT>
<FORM NAME="parentForm">
<INPUT TYPE="button" VALUE="Open child" onClick="openChild
('page2.html','win2')">
<BR><INPUT NAME="pf1" TYPE="TEXT" VALUE="">
<BR><INPUT NAME="pf2" TYPE="TEXT" VALUE="">
</FORM>

 

Page 2

<SCRIPT LANGUAGE="JavaScript">
<!--
function updateParent() {
    opener.document.parentForm.pf1.value = opener.document.parentForm.pf1.value + document.childForm.cf1.value;
    opener.document.parentForm.pf2.value = opener.document.parentForm.pf2.value + document.childForm.cf2.value;
    self.close();
    return false;
}
//-->
</SCRIPT>
<FORM NAME="childForm" onSubmit="return updateParent();">
<BR><INPUT NAME="cf1" TYPE="TEXT" VALUE="">
<BR><INPUT NAME="cf2" TYPE="TEXT" VALUE="">
<BR><INPUT TYPE="SUBMIT" VALUE="Update parent">
</FORM>

 

 

That Should Do It Just Test It And Play Around With It

Thnx,

Tarun

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.