Eoin Posted May 11, 2012 Share Posted May 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262397-pass-php-variables-from-a-php-file-to-a-html-file/ Share on other sites More sharing options...
.josh Posted May 12, 2012 Share Posted May 12, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/262397-pass-php-variables-from-a-php-file-to-a-html-file/#findComment-1345040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.