How to redirect with javascript in a conditional? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to redirect with javascript in a conditional?

This is my code: $('submit').on('click', function (){ var num = document.getElementById('number').value; if(num !== ' '){ window.location = 'userAuth.htnl'; } }); But after I type something into the DOM element and submit it doesn't redirect. But if I console log my input in the conditional, I see it on the console. Please help.

15th Jun 2018, 4:45 PM
Peter Claver
Peter Claver - avatar
2 Answers
+ 1
try this: $('submit').on('click', function (e){ e.preventDefault(); var num = document.getElementById('number').value; if(num !== ' '){ window.location = 'userAuth.html'; } });
15th Jun 2018, 5:20 PM
MO ELomari
0
thanks so much it worked
15th Jun 2018, 5:27 PM
Peter Claver
Peter Claver - avatar