0

Javascript code is not working properly. please help!

This tiny Js code is not working properly. Actually it is not correctly showing the status of progress bar. Dont know why. Please help me figure it out. link to code is given below: https://code.sololearn.com/W0A16a0a203A

23rd Mar 2021, 7:00 AM
Harsh Bhardwaj
Harsh Bhardwaj - avatar
6 Réponses
+ 2
your button (<input type="submit">) is a submit button, meaning it try as default behavior to query a page by sending form data to server after the onclick event... the simplest way to fix it (load a new blank page as no url was provided in the associated form) is to change type to "button" and add a value attribute (wich reflect the button text): <input onclick="progStat()" type='button' value="apply">
23rd Mar 2021, 7:15 AM
visph
visph - avatar
23rd Mar 2021, 11:25 AM
Matias
Matias - avatar
+ 1
Thanks you so much guys. I realized my mistake.
24th Mar 2021, 12:44 PM
Harsh Bhardwaj
Harsh Bhardwaj - avatar
+ 1
because without form context <button> has no special meaning/behavior, but inside form context, default behavior of button is type="submit": you must add type="button" to it inside form to let it work without submitting the form ;)
24th Mar 2021, 1:03 PM
visph
visph - avatar
0
But I'm wondering why <button> element is not working inside <form> element. It is working outside. While <input> element is working inside it.
24th Mar 2021, 12:46 PM
Harsh Bhardwaj
Harsh Bhardwaj - avatar
0
visph Got it. Thanks.
3rd Apr 2021, 4:57 PM
Harsh Bhardwaj
Harsh Bhardwaj - avatar