1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to write text in the document?

Discussion in 'JavaScript' started by mark103, Mar 26, 2013.

  1. #1
    Hi guys,

    I am working on my javascript to create the text in the html document. I want to know how I can write the text in html?

    I tried to use this:

    var test=myFunction();
    
    function myFunction(test)
    {
      var keycode;
      if (window.event) keycode = window.event.keyCode;
      {
        document.write("hello! this is a test");
      }
    }
    Code (markup):


    It did not write the text in the html. I tried to find the solution but i can't.

    Can you please help me?

    thanks in advance.
     
    mark103, Mar 26, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Best thing would be is to use jQuery. You can use selectors to insert the html into specific areas like below.

    
     
    <!DOCTYPE html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
      // define function
      function myFunction() {
          $('body').html('<h1>New HTML Code Inserted');
      }
      // call function
      myFunction();
    });
    </script>
    </head>
    <body>
     
    </body>
     
    
    HTML:
    This should get you started in the lovely world of jQuery.
     
    HuggyStudios, Mar 27, 2013 IP
  3. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Can you tell me what is jQuery?

    Can they work with JavaScript and php at the same time?

    How I can find out if my web hosting have got them in the control panel?
     
    mark103, Mar 27, 2013 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    jQuery is a fat bloated library used by inept retards to piss all over websites because they don't know how to use javascript properly or want to throw it at everything for goofy animations that have no business on a website, or is CSS' job. I pity the people too stupid to realize how badly they are {explitive omitted} over their own websites with it. Ah, the asshat world of jQuery.

    As to your question, I'm not sure I'm following what the devil you are even trying to do... It looks like something javascript shouldn't even be doing in the first place -- Are you trying to capture a keypress? why are you sending that function to a variable? Is there more code than that we're not seeing because to be frank, that's 100% gibberish.

    ... and even if you were doing it on keypress, once the page is loaded doing a document.write will erase the entire page, and I suspect that is NOT what you are trying to do. It almost sounds like what you want to do should be handled using the DOM -- but without a better explanation of what you are trying to accomplish I wouldn't even ATTEMPT to try and make code for that.

    Hell, passing the function to itself should it actually get called would create an endless loop... so that's even WORSE gibberish.
     
    deathshadow, Mar 28, 2013 IP
  5. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Well look, i am newbie on this and i don't know what is all about and your post is not making any sense at all so don't be a fucking retard. I don't expected to a retard like you being a dick over the Internet to showed it off his skills so grow up and show your fucking respect to the society who don't know much about what jQuery supposed to do. You are a twat.

    I am not going to answer your question as you a retard, so think TWICE before you say something to somebody else if you want them to not be rude to you or show respect.
     
    Last edited: Mar 28, 2013
    mark103, Mar 28, 2013 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Wow, the insulting part wasn't even directed at YOU, but at jQuery as a way of warning you AWAY from it -- just as I would warn you away from Dreamweaver or tell you if you really wanted to use Wordpress you should gut out half of what it tries to shove down your throat for markup...

    As to the rest, you don't even want to explain what you want to do? Just how are we supposed to help you do it then? Nope, straight to the kneejerk reaction rather than taking the time to understand the intent or explain what you are trying to do.

    Unless you're upset I called your code gibberish -- if you're just starting out this surprises you?!? Whiskey Tango Foxtrot?
     
    deathshadow, Mar 28, 2013 IP
  7. jhine

    jhine Active Member

    Messages:
    25
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    53
    #7
    Hi there!

    Working on the basis of the title, you're looking to output the the browser? Ensure the below is within the body section of the document as shown.
    <body>
    <script type="text/javascript">
    document.write('Hello World');
    </script>
    </body>
    HTML:
    This will output Hello World to your browser.
     
    Last edited: Mar 28, 2013
    jhine, Mar 28, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    No it won't... you didn't put the javascript in SCRIPT tags.
     
    deathshadow, Mar 28, 2013 IP
  9. jhine

    jhine Active Member

    Messages:
    25
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    53
    #9
    Kudos. I thought it was looking a tad bare ;)
     
    jhine, Mar 28, 2013 IP
  10. kutchbhi

    kutchbhi Active Member

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    70
    #10
    OP for testing , just use
    console.log("my test")
    and see the output in firebug (google it) / chrome dev tools.

    If you want to create text inside html, then instead of document.write , explore innerHTML. Something like : InnerHTML isn't recommended ( I don't know why) , but it should get you on the right track. :)

    
    post = document.getElementById("SomeId");
    post.innerHTML = "yo";
     
    
    Code (markup):
     
    kutchbhi, Mar 29, 2013 IP
  11. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #11

    jQuery is a framework for JavaScript and the main advantage of using this is that it works across the board on all browsers.

    This won't effect anything that your site has in terms of PHP as JavaScript works on client end not server.

    Check out the site here: http://jquery.com/
     
    HuggyStudios, Mar 29, 2013 IP