Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dropdown list and some radio buttons to be selected on a form by the user.
The form on submission must throw an alert saying,"please select a value from dropdown/radiobutton".
Can anyone please tell me how I can achieve this using javascript validation?
I tried using required attribute for dropdown but I am not aware how I can make it show an alert if not selected..
Posted

1 solution

try to get from this simle code :

XML
<html>
    <head>
        <title>Untitled</title>
        <script type="text/javascript">
            function checkit(){
                if(!document.getElementById("cid").checked){
                    alert("Check the checkbox")
                }
                else{
                    a.submit();
                }
            }
        </script>
    </head>
    <body><form id="form1">
        <input type="checkbox" id="cid"/>
        <input type="button" value="Submit" onclick="javascript:checkit();"/>
        </form>
    </body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900