php - javascript - pass a value from parent to child window and within a function -


i've form contains several images. once user clicks whichever image popup window thumbnails come up. once clicks whichever thumbnail, source image in parent window needs replaced according user selection (swapping original image). following script works fine 1 image since logo1 , placeholder1 variables hard coded. how can send image id parent window popup window, following dynamic?

editpage.editform.logo1.value = oname

editpage. placeholder1.src = " images/user/" + oname;

btw, images name’s , id’s in main window subject changed according form template.

template.php

<script type="text/javascript"> function logowin() { window.open('logos.php','logos','height=500,width=700,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'); } </script>  <form action="" id="editform" name="editform" enctype="multipart/form-data"> <img src=”images/user/logo1.jpg” name="placeholder1" id="placeholder1" onclick='logowin()'> <img src=”images/user/logo2.jpg” name="placeholder2" id="placeholder2" onclick='logowin()'> <img src=”images/user/logo3.jpg” name="placeholder3" id="placeholder3" onclick='logowin()'>  <input type="hidden" name="logo1" value="<?php echo $main_logo1; ?>" /> <input type="hidden" name="logo2" value="<?php echo $main_logo2; ?>" /> <input type="hidden" name="logo3" value="<?php echo $main_logo3; ?>" />  <input type="submit" value="save" id="save"> </form> 

logos.php

<script language="javascript">     function getfile(oimg){         editpage = eval(window.opener.document)         osrc = oimg.src;         lastslash = osrc.lastindexof('/');         oname = osrc.substr(lastslash+1);         editpage.editform.logo1.value = oname         editpage. placeholder1.src = " images/user/" + oname;         this.close()     }     </script>     [php loop] <img src='images/user/".$row->img_file_name."' onclick='getfile(this)'> <img src='images/user/".$row->img_file_name."' onclick='getfile(this)'> <img src='images/user/".$row->img_file_name."' onclick='getfile(this)'> 

why using

eval(window.opener.document); 

you can use

var editpage = window.opener.document; 

you can pass id url of page given below

function logowin(id) {     window.open('logos.php?id='+id,'logos','height=500,...'); } 

pass id function paarameter, (logowin(1), logowin(2)) given below

<img src=”images/user/logo1.jpg” name="placeholder1" id="placeholder1" onclick='logowin(1)'> <img src=”images/user/logo2.jpg” name="placeholder2" id="placeholder2" onclick='logowin(2)'> 

in logos.php file, id using

$id = $_get['id']; // 1 or 2 or 3 , on 

then, can use javascript variable like

function getfile(oimg){     var id = <?php echo $id; ?>;     editpage = eval(window.opener.document);     osrc = oimg.src;     lastslash = osrc.lastindexof('/');     oname = osrc.substr(lastslash+1);     var logo = 'logo'+id, placeholder = 'placeholder'+id;     editpage.editform[logo].value = oname;     editpage[placeholder].src = " images/user/" + oname;     this.close(); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -