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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    document.write PLEASE HELP

    I'm trying to get this to work in Magento CMS, so need it to write the returned value (which is a phone number) into a page, but at present it is writing the phone number but on a blank page (so getting rid of everything else) I think because of the document.write
    Is there anyone who can tell me how to do this so it writes the phone number in the space I put this code???
    Much appreciated!

    <script>jQuery(document).ready(function(){document.write(jQuery(".fulfiller-contact-telephone").text())});</script>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You will need to have span or a div with an ID then your code would be
    Code:
    <script type="text/javascript">jQuery(document).ready(function(){
    var phone = jQuery(".fulfiller-contact-telephone").text();
    jQuery('#phonehold').append(phone);
    });</script>
    Then where you want the number to display add
    Code:
    <span id="phonehold"></span>
    Another option would be to copy the html that holds the phone number to where you want it.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    ufgcorp (05-23-2012)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded. However, you can use it to write to child pages.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thankyou, exactly what I needed. Very much appreciated!

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The only time you need to use document.write to create child pages instead of using a server side script is if you are running the script in the browser itself and not in any specific web page. One such example would be a script that generates a copy of the current page source with nice links to all of the files it uses where the page to display that source is generated using a document.write statement in the userscript attached to the browser.

    There is never any need for document.write in scripts attached to a web page directly.

    Since attaching scripts to the browser rather than to a web page is a more advanced topic, document.write has no place in beginners or intermediate JavaScript courses - it belongs in the advanced course as that's the only place where it is needed.
    Last edited by felgall; 05-23-2012 at 11:06 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    As felgall has said, your course was really "A History Of JavaScript". It may have been fine in 1999. Not in 2012.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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