Friday, June 8, 2018

Pass Iframe value to parent page using java script

    parent.document.getElementById('reasonidParent').value= document.getElementById('reasonid').value;;

After Select in html, Change ifame values using php and java script

Steps
01.when select call onchange event in java script
02.Then ammend value to iframe src like (var val='reason.php?id='+selectoptionvalue;)
03. chenge iframe src using setAttribute like window.document.getElementById('frmreason').setAttribute("src",val); 
04. Then get that id value in iframe page using $_GET['id']

======================CODE======================================
In main page....
IN Select????????????????????????????????????
SELECT id='unitFRM' NAME='unit'onchange="reload_message_frame()"   
............................................................
In IFRAME????????????????????????????????iframe id="frmreason" src="reason.php" style="width: 230px; height: 50px;border:none" onload="test()" 
..........................................................................   
Add Java Script AS....

//reloadreason list within ifram in change src
function reload_message_frame() {
    var frame_id = 'frmreason';
       // add UNIT ID TOURL
       var idunit = document.getElementById('unitFRM').value;    
       var val='reason.php?id='+idunit;
    window.document.getElementById('frmreason').setAttribute("src",val);
}

In IFRAME PAGE (reason.php)

 if(isset($_GET['id'])){
     

    $idunit=$_GET['id'];

//set $idunit as you wish