Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Project that makes a grid and on click adds color to a cell.
  2. So the forum mentor told me to start it this way with the handler...
  3. 1.
  4. function makeGrid() {
  5. for (let i = 0; i < pHeight.value; i++) {
  6. const row = pCanvas.insertRow(i);
  7. for (let j = 0; j < pWidth.value; j++) {
  8. const cell = row.insertCell(j);
  9. cell.addEventListener('click', function() {
  10. this.style.backgroundColor = colorPicker.value;
  11. })
  12. }
  13. }
  14. }
  15. So I made the cellClickAddColor on mousedown whether LMB or RMB that adds or clears a cell.
  16. Then I added cellHoverAddColor, same principle.
  17. Then cellClear, again, same way to do it.
  18. Then I wanted to make a input submit (id btn1) to be disabled (unclickable) when there is not a single colored cell, and enabled when there is at least 1 colored one. Wanted to put it inside the hover to check it when it enters a cell for all cells and then do it's job.
  19. Then I could just put manually btn1.disable=false/true to each button, but that's bad or good practice? I guess bad.
  20. So I wanted to make a function cellColorCheck that would check the cells for colored ones and if there is to place btn1.disabled=false;
  21. Now I tried several ways but it doesn't work with using the cell from the makeGrid() iteration.
  22. How do I do it?
  23. Was going this way overall bad?
  24. Is this even possible or do I have to go around it and make it differently?
  25. I am a newbie so I ask people to tell me because I don't know :)
  26. Thanks for your time!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement