How to check the validation of js files or html files including js?

Discussion in 'Javascript' started by independent, Jan 12, 2020.

  1. independent

    independent

    Joined:
    Nov 23, 2019
    Messages:
    59
    Likes Received:
    1
    I returned back (from DOM to objects and would see one very simple sample in real application but that is not running as I expect or understand.

    see that sample here:


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> javascript simple sample</title>
    <script>
    var hotel = {
    name: 'park',
    rooms: 77,
    booked: 34,
    salinta: function() {
    return this.rooms - this.booked;
    }
    };
    var elName = document.getElementById('hotelName');
    elName.textContent = hotel.name;

    var elRooms = document.getElementById('rooms');
    elRooms.textContent = hotel.salinta();
    </script>
    </head>
    <body>
    <div id="hotelName"></div>
    <div id="rooms"></div>
    </body>
    </html>

    but more than the sample,I think I should be able to check the validation of such files (or only js files). when I check this html form W3C validation,it returns no error,but it is not running. :(
     
    Last edited: Jan 12, 2020
    independent, Jan 12, 2020
    #1
    1. Advertisements

  2. independent

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    83
    Likes Received:
    10
    I have never found a validation for JS that I trusted. I write pieces of code and verify myself - then add them to the large script. As for your code - It is doing what it the code says and working correctly. What did you want it to do?

    Three things:
    First place your JS after your HTML code, but before the </body> tag. That allows the HTML to execute faster and get the web site up and running for the user.

    Next, I use alerts to see where I am and what variables are doing. Modern day is to use the console. Your choice.

    Lastly, I changed the amount of rooms booked - ran - code and got the correct number of rooms available. GOOD!
    Code (Text):

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> javascript simple sample</title>

    </head>
    <body>
    <div id="hotelName"></div>
    <div id="rooms"></div>

    <script>
    var hotel = {
      name: 'park',
      rooms: 77,
      booked: 34,
      salinta: function() {
      return this.rooms - this.booked;
      }
    }

    var elName = document.getElementById('hotelName');
    elName.textContent = hotel.name;

    hotel.booked = 41;
    var elRooms = document.getElementById('rooms');
    elRooms.textContent = hotel.salinta();
    </script>
    </body>
    </html>
     
    If your still here look at this site:
    http://xahlee.info/js/js_textContent_innerHTML_innerText_nodeValue.html
     
    sunfighter, Jan 12, 2020
    #2
    1. Advertisements

  3. independent

    independent

    Joined:
    Nov 23, 2019
    Messages:
    59
    Likes Received:
    1
    hi sunfighter ,welcome once again.
    both the thing I was thinking is correct (but not as exactly as I was thinking ) and it is really running now as you said.

    mm,I was only trying to make exercises but failed unfortunately.

    and how can we make better exercises under the information you provided here.
    as you know browser is neglecting all of javascript codes when it comes across any failure
    how to pass this matter?

    thanks
     
    independent, Jan 12, 2020
    #3
  4. independent

    independent

    Joined:
    Nov 23, 2019
    Messages:
    59
    Likes Received:
    1
    independent, Jan 12, 2020
    #4
  5. independent

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    83
    Likes Received:
    10
    No it is not. And I use innerHTML. My mentor hates that - says it's wrong as it makes the page reload and wastes time, but I have a macro setup and just continue using it
     
    sunfighter, Jan 12, 2020
    #5
  6. independent

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    83
    Likes Received:
    10
    When I'm trying to help someone that has a long complicated JS script I first pretty the file so the indentions are nice, then collapse the sections add alert("DONE to my specs"); at the end of the file (a macro) and start commenting sections out til the code runs. Last one is in error so I place it in a separate file and study it.
     
    sunfighter, Jan 12, 2020
    #6
  7. independent

    independent

    Joined:
    Nov 23, 2019
    Messages:
    59
    Likes Received:
    1
    so,normally you are not Xah Lee
    ok.

    I also think it would be wrong (but not for you,currently for me or someone who are not as good as required in js) :) it may cause xxs as you know. I learnt something about it but do not think that the consistence of the magic, would be only not allowing special characters (required characters) in all inclusive areas in html document.

    simpy or with more understandable form,I think the scope of xxs should be wider.

    I see.
    that lso shows you enjoy your study area.
    I appreciate it.
     
    independent, Jan 12, 2020
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.