Advertisement
Guest User

test.js

a guest
Jun 1st, 2019
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function lightStars(e) {
  3.    var starNumber=e.target.alt;
  4.    var stars= document.querySelectorAll("span#stars img");
  5.    for(var i=0; i<starNumber; i++){
  6.       stars[i].src="bw_star2.png";
  7.    }
  8.    for(var i=starNumber; i<5; i++){
  9.       stars[i].src="bw_star.png";
  10.    }
  11.    document.getElementById("rating").value = starNumber+"stars";
  12.    e.target.addEventListener("mouseleave", turnOffStars);
  13.    e.target.addEventListener("click",
  14.       function(){
  15.      e.target.removeEventListener("mouseleave", turnOffStars);
  16.       }
  17.    );
  18. }
  19.  
  20.  
  21.  
  22. function turnOffStars(){
  23.    var stars= document.querySelectorAll("span#stars img");
  24.    for (var i=0; i<5; i++){
  25.       stars[i].src="bw_star.png";
  26.    }
  27.    document.getElementById("rating").value="";
  28. }
  29.  
  30. function updateCount(){
  31.    var commentText = document.getElementById("comment").value;
  32.    var charCount = countCharacters(commentText);
  33.    var wordCountBox = document.getElementById("wordCount");
  34.    wordCountBox.value = charCount + "/1000";
  35.    if (charCount > 1000){
  36.       wordCountBox.style.color = "white";
  37.       wordCountBox.style.backgroundColor = "red";
  38.    } else{
  39.       wordCountBox.style.color = "black";
  40.       wordCountBox.style.backgroundColor = "white";
  41.    }
  42. }
  43.  
  44.  
  45.  
  46. function countCharacters(textStr) {
  47.    var commentregx = /\s/g;
  48.    var chars = textStr.replace(commentregx, "");
  49.    return chars.length;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement