Results 1 to 6 of 6

Thread: Not so messy javascript

  1. #1
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default Not so messy javascript

    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

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You can actually use file_get_contents in js with a little bit of PHP, search it:
    http://www.google.com/search?q=file_...ient=firefox-a
    With that you can use: getElementById(...).innderHTML=file....
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    hosdank (08-21-2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default

    Thanks so much!

  5. #4
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default

    Any idea why this won't work? It just dosn't do anything
    Code:
    <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);
        req.send(null);
     
        return req.responseText;
    }
    
    	var filecontents;
    	filecontents=file_get_contents('http://localhost/spacetrade/HTML & Code/blah.php');
    	document.write(filecontents);
    </script>

  6. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    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:
    http://forums.tizag.com/showthread.php?t=3496
    Jeremy | jfein.net

  7. The Following User Says Thank You to Nile For This Useful Post:

    hosdank (08-22-2008)

  8. #6
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default

    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •