It’s often the case in development you’ll find yourself embedding brand new code with the old. The simplest of commands can go a long way to making the content exchange easier. The code window.opener.document.getElementById, is a great way to pass information between webpages (the old and the new) that need to coexist. The scenario could be passing data between a parent window and child or using hidden popups. Here is a PHP example to update checkboxes on a parent window (or launching page) echoing javascript code.


//Initialize an array of checkboxes
$array_checkbox = array("chk_name1", "chk_name2", "chk_name3", "chk_name4");
$i = 0;
while($i<=4){
    $chkname = $array_checkbox[$i];
    echo "<script type=\"text/javascript\">";
    echo "window.opener.document.getElementById('$chkname').checked=true; </script>";
    $i++;
}

Wasn’t that quick and easy! You’ll notice that you could just as easily replace the checkbox names with div’s, radio buttons or anything that needed to have its value/property modified. This opens a world of possibilities for you doesn’t it?
 

Leave a reply

required

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>