can someone tell me why this code take me to sololearn site instead of w3schools when I click the button? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

can someone tell me why this code take me to sololearn site instead of w3schools when I click the button?

<!DOCTYPE html> <html> <body> <form onsubmit="return validate()" method="post"> Number: <input type="text" name="num1" id="num1" /><br /> Repeat: <input type="text" name="num2" id="num2" /><br /> <a href="https://www.w3schools.com"> <input type="submit" value="Submit" /> </a> </form> <script> function validate() { var n1 = document.getElementById('num1'); var n2 = document.getElementById('num2'); if(n1.value !== '' && n2.value !== '') { if(n1.value == n2.value) { return true; } } // alert("The values should be equal and not blank"); return false; } </script> </body> </html>

29th Mar 2019, 12:23 AM
Glory222
Glory222 - avatar
10 Answers
+ 2
Glory S just add the action, just like I did in my answer
30th Mar 2019, 12:07 AM
Mike
Mike - avatar
+ 8
or u could do it say target=“_blank”
29th Mar 2019, 8:56 PM
ANONYMOUS
ANONYMOUS - avatar
+ 4
you’r welcom Glory S
8th Apr 2019, 7:49 PM
ANONYMOUS
ANONYMOUS - avatar
+ 3
Takes you to sololearn because you don’t have an action in your form. The href you have has absolutely nothing to do with the form. It’s just a link between your inputs and submit button. For the form to send to w3schools, you need: <form onsubmit="return validate()" method="post" action=“https://www.w3schools.com”>
29th Mar 2019, 3:50 AM
Mike
Mike - avatar
+ 3
hey Glory S take a look at this might help you it has what you need to go to w3schools https://code.sololearn.com/W2SwknROZXuE/?ref=app
9th Apr 2019, 10:51 AM
ANONYMOUS
ANONYMOUS - avatar
+ 2
Also, when a form doesn’t have the action included, it’s automatically submitted to itself, aka the url it’s at. That’s why if the form is at sololearn, it’ll be submitted to sololearn.
29th Mar 2019, 6:44 PM
Mike
Mike - avatar
+ 2
Mike could you please rewrite this code for me and make it go to w3schools.com when clicked? Thanks
29th Mar 2019, 7:14 PM
Glory222
Glory222 - avatar
+ 2
How?
29th Mar 2019, 9:52 PM
Glory222
Glory222 - avatar
+ 2
Thanks
6th Apr 2019, 5:29 PM
Glory222
Glory222 - avatar
+ 2
Thanks bro
9th Apr 2019, 11:21 AM
Glory222
Glory222 - avatar