Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to draw a line between 2 boxes, but only once, whenever i click again, i see the line is getting thicker and thicker. I really need to execute it once cause later on I need to save it to a db, and I dont want redundant data, if it keeps saving/drawing when its executed.

var try1 = true
window.addEventListener("keydown",check,false && try1 ==true);
function check(key) {
if (key.keyCode == "65") {


c.beginPath();
c.moveTo(150,150);
c.lineTo(300,150);
c.strokeStyle ="red";
c.stroke();
try1 = false;
}}

What I have tried:

I tried whats in the link, and tried to use af for loop. I sadly didnt succeed yet!!!

Posted
Updated 11-Oct-18 0:58am

1 solution

Put the "try1" check in the check method

var try1 = true
window.addEventListener("keydown",check);
function check(key) {
if (try1 == true && key.keyCode == "65") {
 
Share this answer
 
v2
Comments
Member 14015933 11-Oct-18 7:37am    
thank for your reply, but I Tried that too didnt work :/
F-ES Sitecore 11-Oct-18 7:42am    
Sorry, I meant

if (try1 == true && key.keyCode == "65") {

I've updated the solution
Member 14015933 11-Oct-18 7:48am    
thank you again, your comment led me to the solution, this worked so far.

var try1 = true;
window.addEventListener("keydown",check,false);
function check(key) {
if (key.keyCode == "65" && try1 == true) {


c.beginPath();
c.moveTo(150,150);
c.lineTo(300,150);
c.strokeStyle ="red"; //use hex #code

c.stroke();
try1 = false;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900