rizwansyed Posted August 20, 2018 Share Posted August 20, 2018 Hi I have a code in which i am running a script for drop-down list to show only the selected drop-down content as shown in attached file. I need to add one more script file for alerting a warning for unselected drop-down list as shown below <input type="submit" value="submit" onclick="return Validate()" /> <script > function Validate() { var abc = document.getElementById("opts"); if (abc.value == "") { //If the "Please Select" option is selected display error. alert("Please select an option!"); return false; } return true; } </script> How can i merge two script files or anyway to call both files Please suggest Thanks and Regards Rizwan Syed adding one more script file.txt Link to comment Share on other sites More sharing options...
dsonesuk Posted August 20, 2018 Share Posted August 20, 2018 You don't use onclick on submit button, but! onsubmit on form tag itself Link to comment Share on other sites More sharing options...
rizwansyed Posted August 25, 2018 Author Share Posted August 25, 2018 Thanks for the reply. I didnt get exactly what u mean to say but i tried <form action="/action_page.php" method="post" autocomplete="off" onsubmit="Validate()"> with two script files but didnt get it work. Can you just explain once again Link to comment Share on other sites More sharing options...
dsonesuk Posted August 25, 2018 Share Posted August 25, 2018 (edited) Placing onsubmit on the form element ONLY! Will capture ALL form submission achieved by clicking any button that acts like a type submit, or a non 'required' input/s where a user will press the keyboards 'Enter' key while in the input, that will trigger a submission event. So to properly validate using a validation function whenever a submission occurs it should run by the onsubmit event that is always applied to the form element and nowhere else. Edited August 25, 2018 by dsonesuk Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now