Results 1 to 4 of 4

Thread: Need this javascript code to work on this website

  1. #1
    Join Date
    Jun 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need this javascript code to work on this website

    I need to make my code work in this website
    http://www.pcsoresult.com/swertres-lotto-results/

    specifically I need only the results shown on the 11, 4 , 9 draws.
    selected sources
    Code:
    <p data-iceapc="3" data-iceapw="10">11am <span class="IL_AD" id="IL_AD2">Draw</span>: <strong data-iceapw="1" class="winning-numbers">9-8-4</strong><br>
    4pm Draw: <strong data-iceapw="1" class="winning-numbers">2-2-2</strong><br>
    9pm Draw: <strong class="winning-numbers"></strong></p>
    I use getElementsbyClassName to get the text because each draw has a "winning-numbers" class name.
    Code:
    <script>
    var number = document.getElementsbyClassName("winning-numbers")
    document.write(number)[0];
    document.write(number)[1];
    document.write(number)[2];
    but I supposed it's not working

    I need help here if someone can. I know it is easy task because we can get the value easily by using getElementsbyClassName method.
    Last edited by Beverleyh; 06-07-2015 at 11:55 AM. Reason: formatting

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Are you just trying to grab the innerHTML as a string? i.e. The "9-8-4" part of the 11am line, "2-2-2" part of the 4pm line, and something similar for the 9pm line when a value is present?

    getElementsByClassName() should work OK for modern browsers and IE9+, but watch your syntax! - there's a capital "B" in there. Also, document.getElementsByClassName() returns a nodeList, not an element, so if you want to get the innerHTML of an element this way, you need to do it like this;
    Code:
    document.getElementsByClassName("winning-numbers")[0].innerHTML;
    The example above gets the innerHTML of the first element with the "winning-numbers" class.

    Im not sure what are you doing with the data once you have it because your page is crashing my browser (therefore I can't see from the source code), but if you want to insert the retrieved data into an existing element, try innerHTML() https://developer.mozilla.org/en-US/...ment/innerHTML

    Note that document.write() is only useful while the page is loading and being generated for the first time, and when the script is run from the <head> of a web page. For dynamically updating the page after it has been generated, or for when a script is placed before the closing </body> tag, innerHTML() is probably a better choice.

    So if you want to get the innerHTML of all 3 elements and then insert the values as innerHTML into 3 other elements, you could do it simply like this;
    Code:
    <body>
    
    <p data-iceapc="3" data-iceapw="10">11am <span class="IL_AD" id="IL_AD2">Draw</span>: <strong data-iceapw="1" class="winning-numbers">9-8-4</strong><br>
    4pm Draw: <strong data-iceapw="1" class="winning-numbers">2-2-2</strong><br>
    9pm Draw: <strong class="winning-numbers">XXX</strong></p>
    
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>
    
    <script>
    document.getElementById('test1').innerHTML = document.getElementsByClassName("winning-numbers")[0].innerHTML;
    document.getElementById('test2').innerHTML = document.getElementsByClassName("winning-numbers")[1].innerHTML;
    document.getElementById('test3').innerHTML = document.getElementsByClassName("winning-numbers")[2].innerHTML;
    </script>
    
    </body>
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Jun 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes I want to get the strings of the class name winning numbers

    Thank you for the response regarding my question. I just want to ask one more time so there is no need to load the url or site which the classnames are came from or I could just directly implement the GetElementsbyClassName method without the url as the class reference.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Sorry, I'm not sure I understand the question.

    Is pcsoresults.com not YOUR website?

    You might want to read up on "same origin policy" which only permits scripts running in a browser to make requests to pages on the same domain.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. The codes don't work on my website
    By Godji in forum HTML
    Replies: 6
    Last Post: 07-29-2011, 08:17 PM
  2. Javascript code wont work
    By weido in forum JavaScript
    Replies: 3
    Last Post: 05-22-2010, 07:04 PM
  3. javascript code not work in firefox
    By rushiags in forum JavaScript
    Replies: 1
    Last Post: 01-08-2009, 03:14 PM
  4. Replies: 4
    Last Post: 12-25-2008, 02:58 PM
  5. Does Javascript work on AJAX generated code?
    By spyd3rr in forum JavaScript
    Replies: 14
    Last Post: 11-13-2007, 10:45 PM

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
  •