Check to see something is selected from either of the two dropdowns

Posted on 2011-10-30
Last Modified: 2012-05-12
I have the following JavaScript to check character length of the form if it's greater than 150 and if it is, the user is alerted.

When you look at the file attachment which is a screen print of the web form page.

It has two dropdowns for the user to select from. I need a function to check that something is selected from either one of the two dropdowns before the "Send" button is clicked. This is a homemade paging system for my company.

If they click the send button and nothing is selected from either of the dropdowns then an alert window should pop-up similar the way the function CountChr works. This function alerts the user that they have a long message in the Your Message textbox.


function CountChr(){
myLength = document.myform.YourMessage.value.length + document.myform.YourName.value.length + document.myform.YourNumber.value.length + 11
     if (document.myform.Type.value == "Group"){
	myLength = myLength + 10
              ChrCount.innerHTML = myLength + "/150"
	if (myLength > 149){
	alert("You can only send a maximum of 150 characters in a page.")
PageMessage.innerHTML = "From: " + document.myform.YourName.value + " @ " + document.myform.YourNumber.value + ", " + document.myform.YourMessage.value
function ResetForm(){
	PageMessage.innerHTML = ""
	ChrCount.innerHTML = ""

Open in new window

Screen print of form
Question by:rkckjk
    LVL 81

    Accepted Solution

    Test page :
        var dropdown_Individual = document.myform.Individual_field_name;
        var dropdown_Group = document.myform.Group_field_name;
        if( dropdown_Individual.selectedIndex + dropdown_Group.selectedIndex == 0 ) {
             alert("You must choose Indivdual or Group!")
             return false;
        return true;

    Open in new window

    LVL 2

    Author Comment

    On my form I have the following:

    <form name="myform" action="http://xxxxx.xxxxx.xxxx/alphapage/" method=post>

    This excutes the Perl script that actually sends out the page.

    So, how would I change it to use your solution.

    You have the following:

    <form name="myform" onsubmit="return validateDropdown()">
    LVL 2

    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now