JS if & else not working..!😕 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

JS if & else not working..!😕

See JS code, after I click the Submit button if I have not filled anything in the input field, it gives an alert.....but even if I write something in the input field, it even then gives an alert......is there any fault in the JS code, please tell me https://code.sololearn.com/W0e908sXyZjU/?ref=app

14th Oct 2021, 6:11 AM
Parth
Parth - avatar
6 Answers
+ 6
var badgeName = $("#badgeName"); That line references the object, and not the string(value) inside that object.
14th Oct 2021, 6:30 AM
Arturop
Arturop - avatar
+ 9
Hi bro I'll start again with the JS and explain you, I don't master jquery.
14th Oct 2021, 6:19 AM
Faxel࿐
Faxel࿐ - avatar
+ 4
Line 7: if (badgeName.length < 0) Should've been if (badgeName.length > 0)
14th Oct 2021, 6:24 AM
Ipang
+ 4
Ipang but it's still not working😕
14th Oct 2021, 6:28 AM
Parth
Parth - avatar
+ 3
Arturop perfect, now it's working😃 Thankyou soooooooooooooooo much 😄
14th Oct 2021, 6:32 AM
Parth
Parth - avatar
14th Oct 2021, 6:23 AM
Parth
Parth - avatar