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

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
Richard KreidlSoftware DeveloperAsked:
Who is Participating?
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

Richard KreidlSoftware DeveloperAuthor Commented:
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()">
Richard KreidlSoftware DeveloperAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.