3
\$\begingroup\$

I been writing code for my company for years and there is never any constructive criticism for what I do. I am the only developer here and I would appreciate your opinion on this web page I made. It grabs data from a mssql database and places it in a data table adds some calculations then displays the data in a gridview. I added some css and javascript to make it look better. But is my javascript too sloppy.

link: to codepen.io

<script>
    jQuery(function () {

          $(document).ready(function () {
              var xd = document.getElementById("datepicker");
              var xde = document.getElementById("datepicker2");
              var d = new Date();
              var d2 = new Date();

              var parlen = 0;
              var colwidth = document.getElementById('GridView1').rows[0].cells[0].offsetWidth;

              d.setDate(d.getDate() - 2);
              d2.setDate(d2.getDate() - 1);
              xd.value = d.toLocaleDateString();
              xde.value = d2.toLocaleDateString();
              $("th").css("background-color", "#5FE 1");
              $("td:last-child()").css("background-color", "#3FE 1");
              $("td:first-child()").css("background-color", "#EFE 1");

              parlen = $("th").length;

              $("#GridView1 tr td:contains('No Data')").css("background-color", "#EEE 1");
              $("tr:nth-child(2)").css("background-color", "#ba67f0");
              // $("td:nth-child()").hover($(this).css("background-color", "#EFE 1"), $(this).css("background-color", "#F3E 1"));
              $("#GridView1 tr td:nth-of-type(n)").hover(function () {
                  // var pl = this.parent.length();
                  var cb = 1 + this.cellIndex;
                  var rb = 1 + this.parentElement.rowIndex;
                  if (cb > 1 && cb < parlen) {
                      $("td:nth-child(" + cb + ")").css("background-color", "yellow");
                      $("td:nth-child(" + cb + ")").css("font-size", "16px");
                      $("td:nth-child(" + cb + ")").css("font-bold", "true");
                      $("tr:nth-child(" + rb + ") td").css("background-color", "yellow");
                      $("td:last-child()").css("background-color", "#3FE 1");
                      $("td:first-child()").css("background-color", "#EFE 1");
                      // $("td:nth-child(" + cb + ")").css("column-width", 2*colwidth);
                  }
              }, function () {
                  var cb = 1 + this.cellIndex;
                  var rb = 1 + this.parentElement.rowIndex;


                  if (cb > 1 && cb < parlen) {

                      $("td:nth-child(" + cb + ")").css("background-color", "white");
                      $("td:nth-child(" + cb + ")").css("font-size", "12px");
                      $("td:nth-child(" + cb + ")").css("font-bold", "true");
                      $("#GridView1 tr td:contains('No Data')").css("background-color", "#EEE 1");
                      $("tr:nth-child(" + rb + ") td").css("background-color", "white");
                      $("tr:nth-child(2) td").css("background-color", "#ba67f0");
                      $("td:last-child()").css("background-color", "#3FE 1");
                      $("td:first-child()").css("background-color", "#EFE 1");
                  }
              });



          });
</script>
```
\$\endgroup\$
  • \$\begingroup\$ Welcome to CodeReview@SE. Can you please try and improve the title of your question following How do I ask a Good Question? Please check the vertical space in the code block, too. \$\endgroup\$ – greybeard Dec 26 '19 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.