Jump to content

pass php variables from a php file to a html file


Eoin

Recommended Posts

I have currently got a while loop retrieving the relevant data from a database and drawing polygons.On the polygon onClick()action a buildingClick function is called passing a few variables.in that buildingClick function i am trying to pass these variables to a new page to display in a text area but i cant get it to work.the new page opens but doesnt display the variables as intended.

////////////////////////////////////////////////////////////////////////////////////////////////

EXTMAP.PHP

<?php  

            while($info = mysql_fetch_array( $data )){

$id = $info['id'];

$name = $info['name'];

$b_desc = $info['information'];

                echo "<polygon fill=".$info['fill_colour']." stroke=\"black\" onclick=\"buildingClick($id,'$name','$b_desc')\"  points=".$info['coordinates']."/>";

        }

?>

/////////////////////////////////////////

<script type="text/javascript">   

var mywin;

var isOpen = false;

var searchInt;

var passVal;

// This function is called when a building is clicked.   

function buildingClick(id,name,desc)

{

passVal = desc;

mywin = window.location.href = "informationPage.html";

searchInt = setInterval(function(){if(isOpen){mywin.document.getElementById("infoArea").value = passVal; clearInterval(searchInt);}}, 100);

}  

    </script>

//////////////////////////////////////////////////////////////////////////////////

INFORMATIONPAGE.HTML

 

<script type="text/javascript">

window.onload = function(){window.opener.window["isOpen"] = true;};

</script>

 

<div class="infoDiv" id=infoDiv>

  Name: <input type="text" disabled="true" id="bName" />

</div>

/////////////////////////////////////////////////////////////////////////////////////

 

If anybody knows why this isnt working or ow i could make it work it would be much appreciated.

Eoin.

1) Are your php variable values outputting in your js onclick? (view source of rendered page to verify)

 

2) Are the js variables being passed to your buildingClick() function? (use alert() or console.log()  to verify)

 

3) mywin = window.location.href = "informationPage.html"; might possibly be problematic...you are setting the current window's location to a new location too.. stands to reason you are being redirected to informationPage.html before the rest of your js has a chance to execute

 

4) mywin.document.getElementById("infoArea") I see in your informationpage.html the div id is "infoDiv" not "infoArea"

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.