• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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 Kreidl
Richard Kreidl
  • 2
1 Solution
Test page : http://jsfiddle.net/xXp8q/
    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/page.pl" 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:

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now