Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
Actually, you are not getting the expected result because the submit button is working!! When we use <form> tag and in that we use a <input> tag with type attribute set to submit, means the submit button then when we click on the submit button to submit the form what actually goes on behind the scene is that :- If action attribute is specified on the <form> tag then the browser will submit the form data to the specified URL (in the action attribute) and it will navigate you to that URL. If action attribute is not specified on the <form> tag then the browser will try to submit the form data to the page URL (means the webpage URL, that contains the form) itself. It means the browser will still navigate you to the page URL + form data (in the query parameters). So, in the both cases the browser is navigating to the new URL. That's why you are not getting the alert "Your form is registered".
1st May 2021, 5:42 AM
Tabir Sohail
+ 3
No need of if condition I think.. https://code.sololearn.com/WMQsaxqoJnfz/?ref=app
1st May 2021, 5:31 AM
Aditya
Aditya - avatar