Question

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.

Was it helpful?

Solution 2

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>

OTHER TIPS

Solution1;

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

//Use parent window
window.opener.document.ElementUpdater("image1", "image.png");

Try set id to text field:

    <input type="text" name="image" id="image" size="20" value="">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top