0

I have a form like this:

<form action='index.php' method='POST' id='sampleform' name='sampleform'>
    <input type=text name=image size=20 value=''>
</form>

And I want to populate the image field from a popup window.

I'm trying to do it with this:

<a href="#" onclick="window.opener.document
     .getElementById('image').value='<? echo $id;?>';window.close();">
   <? echo $id;?>
</a>

But it doesn't work.

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56
lStoilov
  • 1,256
  • 3
  • 14
  • 30

3 Answers3

1

Solution1;

//Add child window
function ElementUpdater(elemId,param1) {
    document.getElementById(elemId).value = param1;
}

//Use parent window
window.opener.document.ElementUpdater("image1", "image.png");
Ozan ÇAKİN
  • 163
  • 15
0

Try set id to text field:

    <input type="text" name="image" id="image" size="20" value="">
Nostalgie
  • 554
  • 4
  • 5
0

you have to change it like:

<a href="#" onclick="window.opener.document
 .querySelector('input[name=image]').value='<? echo $id;?>';window.close();">
<? echo $id;?>
</a>

if I were you I would do it like:

<a href="javascript:window.opener.document
 .querySelector('input[name=image]').value='<? echo $id;?>';window.close();">
<? echo $id;?>
</a>
Mehran Hatami
  • 12,723
  • 6
  • 28
  • 35