View Full Version : Not so messy javascript

08-21-2008, 09:39 PM
I have a table which contains quite a bit of PHP code(Don't worry, this question IS related to JavaScript). When the user clicks a button I need the PHP code to change. I know I can use getElementById('shade').innerHTML='(PHP CODE INSERTED HERE)' to change it, but the thing is it would be a pain to keep all my PHP code on one line due to it being all wrapped inside a JavaScript command. I'd like to be able to format it with new lines and every thing. Any ideas? Sorry if that wasn't explained well. Thanks :)

08-21-2008, 09:41 PM
You can actually use file_get_contents in js with a little bit of PHP, search it:
With that you can use: getElementById(...).innderHTML=file....

08-21-2008, 09:43 PM
Thanks so much! :)

08-21-2008, 10:12 PM
Any idea why this won't work? It just dosn't do anything

<script language='javascript'>
function file_get_contents( url )
// http://kevin.vanzonneveld.net
// + original by: Legaev Andrey
// % note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
// * example 1: file_get_contents('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
// * returns 1: '123'

var req = null;
try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
try { req = new XMLHttpRequest(); } catch(e) {}
if (req == null) throw new Error('XMLHttpRequest not supported');

req.open("GET", url, false);

return req.responseText;

var filecontents;
filecontents=file_get_contents('http://localhost/spacetrade/HTML & Code/blah.php');

08-21-2008, 11:05 PM
I don't know, but the error says its a security issue, please try one of the other codes on Google I linked you to.
I've also found this one that looks quite promising:

08-22-2008, 06:20 PM
Thanks :)