kensbeijing Posted October 14, 2009 Share Posted October 14, 2009 Ok quite simply this is what I have <div id="box"><?php echo $a1; ?></div><script language="JavaScript">function change() { document.getElementById('box').innerHTML = "<?php echo $a2;?>";}</script> When I call the js function change(), the html inside the div should change so it echos the php variable $a2. But it's not happening, the page doens't load up properly,and I'm guessing it's because I can't mix the php in with the js. How would I change the echoed variable, without using all that fancy AJAX stuff?Variables $a1 and $a2 are pretty big. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 14, 2009 Share Posted October 14, 2009 That will work as long as $a2 has the value you need whenever you print that Javascript code. You may need to escape quotes in the value though if there are any. Link to comment Share on other sites More sharing options...
jeffman Posted October 14, 2009 Share Posted October 14, 2009 View Source in the browser to see what that part of the script actually looks like. Your built-in Firefox error console (or Firebug if you use it) should give you more information.Anyone wanting to use the error console should know that it clutters up VERY QUICKLY, because most pages on the web are full of errors. The most recent (ie, the page you're working on) are at the bottom, so you have to scroll to find them. I personally clear the console (there's a button at the top) almost every time I refresh a page under development. Link to comment Share on other sites More sharing options...
kensbeijing Posted October 14, 2009 Author Share Posted October 14, 2009 Thanks, but I figured out why. My variable was very big, and included many html tags inside, and for some reason it doesn't work with innerHTML. I tried smaller variables with a few words and that worked fine. So my new solution is to use CSS to make the visibility of $a2 hidden, and when the function is called, $a1 becomes hidden and in turn makes $a2 visible. This is a much nicer way, especially in IE, when changing the innerHTML, the text becomes fuzzy. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.