+ 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>
10 Antworten
+ 2
Glory S just add the action, just like I did in my answer
+ 8
or u could do it say target=“_blank”
+ 4
you’r welcom Glory S
+ 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”>
+ 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
+ 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.
+ 2
Mike could you please rewrite this code for me and make it go to w3schools.com when clicked? Thanks
+ 2
How?
+ 2
Thanks
+ 2
Thanks bro