Drop Down Limit?

L

ll

Hi,
I have a form with seven drop down boxes, and I would like to limit the
number used at any one time to one. I've seen this done with check
boxes, but I'm unsure about the syntax, etc., involved with dropdowns.


Thanks
Louis
 
S

Stephen Chalmers

ll said:
Hi,
I have a form with seven drop down boxes, and I would like to limit the
number used at any one time to one. I've seen this done with check
boxes, but I'm unsure about the syntax, etc., involved with dropdowns.
I presume that you mean that whenever one select box is changed, all the
others reset to option 0.

Add this code somewhere in your existing scripts:

JustSelect = /*28432953204368616C6D657273*/
{
one : function( form )
{
for( var i=0, len=form.elements.length; i<len; i++ )
if( (el=form.elements).type=='select-one')
el.onchange=function(){ JustSelect.meOnly( this ) }
},

meOnly : function( selElem )
{
for( var i=0, form=selElem.form, len=form.elements.length; i<len; i++ )
if( (el=form.elements).type=='select-one' && el!=selElem )
el.selectedIndex = 0;
}
};

then after your form is rendered, add:

JustSelect.one( document.forms.myForm );
 
L

ll

Stephen,

Thanks for your help. Where would the " JustSelect.one(
document.forms.myForm );" go? Would that be after the form, in the
body? Are any changes necessary, beyond changing the name of the form
to suit mine?

Thanks


Stephen said:
I presume that you mean that whenever one select box is changed, all the
others reset to option 0.

Add this code somewhere in your existing scripts:
Ste> JustSelect = /*2
8432953204368616C6D657273*/
{
one : function( form )
{
for( var i=0, len=form.elements.length; i<len; i++ )
if( (el=form.elements).type=='select-one')
el.onchange=function(){ JustSelect.meOnly( this ) }
},

meOnly : function( selElem )
{
for( var i=0, form=selElem.form, len=form.elements.length; i<len; i++ )
if( (el=form.elements).type=='select-one' && el!=selElem )
el.selectedIndex = 0;
}
};

then after your form is rendered, add:

JustSelect.one( document.forms.myForm );
 
S

Stephen Chalmers

ll said:
Stephen,

Thanks for your help. Where would the " JustSelect.one(
document.forms.myForm );" go? Would that be after the form, in the
body? Are any changes necessary, beyond changing the name of the form
to suit mine?

Anywhere below the form, so it's not called until the form exists.
No changes are needed to the HTML.
 
L

ll

Stephen,

Thanks for your help - for some reason it isn't working. The only
change I made was in the "JustSelect.one(document.forms.myForm);" line,
as I changed myForm to theForm, as that's the name of the form.

I have another javascript validation code that I'm running on the
"final" form, for the other form elements, via the onsubmit="return..
method. Would it be possible to do this type of dropdown validation
along with the following type of javascript:

=======================
<script language="JavaScript">
// last name

function checkLastName (strng) {
var error = "";
if (strng == "") {
error = "Please enter your last name.\n\n";
}
return error;
}

// department

function checkDepartment (strng) {
var error = "";
if (strng == "") {
error = "Please enter your department.\n\n";
}

return error;
}

// valid selector from dropdown list

function checkClassSession(choice) {
var error = "";
if (choice == 0) {
error = "Please choose a class session from the drop-down
list.\n\n";
}
return error;
}


/**/
<!-- End "validate.js" code -->

<!-- Begin check form script, which refers to "validate.js" code,
listed above -->
<!--
function checkWholeForm(theForm) {
var why = "";
why += checkLastName(theForm.last_name.value);
why += checkDepartment(theForm.department.value);
why += checkClassSession(value);
if (why != "") {
alert(why);
return false;
}
return true;
}
// -->
</script>

---------
here is the way it's called in the body:
<form name="theForm" method="post" onsubmit="return
checkWholeForm(this)"
action="http://www.domain.com/cgi-bin/[email protected]">
----------

Thanks again,
Louis
 
S

Stephen Chalmers

ll said:
Stephen,

Thanks for your help - for some reason it isn't working. The only
change I made was in the "JustSelect.one(document.forms.myForm);" line,
as I changed myForm to theForm, as that's the name of the form.

I have another javascript validation code that I'm running on the
"final" form, for the other form elements, via the onsubmit="return..
method. Would it be possible to do this type of dropdown validation
along with the following type of javascript:
The specified select box behaviour is quite independent from
validation, as it occurs during completion of the form. I cannot help
further without seeing the code (posted on this group).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,159
Latest member
SweetCalmCBDGummies
Top