I'm trying to pass and insert value from child window to the value attribute of text field which located in parent window, and not to its property. I've tried all the following but no luck so far:
Child window:
function getFile(oImg){
var id = <?php echo $id; ?>;
var editPage = window.opener.document;
oSrc = oImg.src;
lastSlash = oSrc.lastIndexOf('/');
oName = oSrc.substr(lastSlash+1);
var logo = 'logo'+id, logoHolder = 'logoHolder'+id;
//window.opener.document.getElementById(logo).value = oName;
//window.opener.document.getElementById(logo).setAttribute("value", oName);
//window.opener.document.getElementById(logo).innerHTML = oName;
//window.opener.document.getElementById(logo).setValue = oName;
window.opener.document.getElementById(logoHolder).src = "templates/img/user/" + oName;
this.close()
}
Parent page:
<input type="text" id="logo1" name="logo1" value="VALUE-SHOULD-BE-INSERTED-HERE" />
The first one just display the value in the text-field but when I'm trying to save it with jquery, the value is actually empty. Any idea?
window.opener.document.getElementById(logo).value = fileName;
This should work—except that logo
should be a string. Otherwise the opened child window will try to find a variable with the name logo
, which it will probably not find.
So, do this:
window.opener.document.getElementById('logo').value = fileName;
No idea what you are doing wrong, maybe the PHP echo won’t output the correct ID? Anyway, it works fine for me. See this example:
<input type="text" id="logo1" value="VALUE-SHOULD-BE-INSERTED-HERE" />
<script>window.open('child.html');</script>
<button id="btn">Click me</button>
<script>
btn.addEventListener('click', function () {
var logo = 'logo' + '1';
window.opener.document.getElementById(logo).value = 'something';
window.close();
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With