+ 1

Javascript button condition

How do I add conditions to my button in javascript

20th Sep 2020, 12:11 AM
Haleu Bv
Haleu Bv - avatar
5 Answers
+ 2
I'm not sure but I understand you correctly, you mean something like this? In the HTML; <button onclick="dothis"> Click be to do alert hu if your condition us true</button> In the JavaSricpt; var condition = true; //This cam be any condition though; function dothis(){ If(conditon==true/*You can make this any condition though, even tho check if 2<1*/){ //What you want to do; } }
20th Sep 2020, 12:45 AM
Vachila64☕
Vachila64☕ - avatar
+ 3
Describe more in Description - what kind of condition is needed, and for what purpose. Clear and descriptive detail attracts contributors 👍
20th Sep 2020, 12:35 AM
Ipang
+ 3
Divya Mohan thanks😅, must have been a typo or something😅
20th Sep 2020, 3:51 PM
Vachila64☕
Vachila64☕ - avatar
+ 1
Vachila64☕ it would be onclick="dothis()" As you r a function here.
20th Sep 2020, 4:08 AM
Divya Mohan
Divya Mohan - avatar