Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    73
    Thanks
    5
    Thanked 9 Times in 9 Posts

    Question Javascript Output to txt file

    How would I change the code below to output into a text or php file instead of the current DOM. I have to bring this calculated output into another file using PHP include because the final page cannot have javascript on it.

    {document.write('<article itemscope itemtype="http://data-vocabulary.org/Review-aggregate"><div itemprop="itemreviewed">ABC 123 Company</div><div>Rated <span itemprop="rating" id="ratingV">' + average + '</span> out of 5 with <span itemprop="count" id="count">' + ct + '</span> Reviews.</div></article>');}

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Despite how you end up doing it – what you are doing is highly critical in terms of security. Anyone can manipulate the JavaScript that you will then gladly inject into your website.

    I suggest you really think about this twice.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    AMEN!

    Forget using JavaScript for this. Use PHP code. Any calculation you do in JS code can instead be done in PHP.

    And *VALIDATE* that the input from the browser that tells the PHP code what to do is legitimate.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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