Drop Down Limit? | | |
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 | | | | re: Drop Down Limit?
"ll" <barn104_1999@yahoo.com> wrote in message
news:1149522166.647303.109090@j55g2000cwa.googlegr oups.com...[color=blue]
> 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.
>[/color]
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[i]).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[i]).type=='select-one' && el!=selElem )
el.selectedIndex = 0;
}
};
then after your form is rendered, add:
JustSelect.one( document.forms.myForm ); | | | | re: Drop Down Limit?
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 Chalmers wrote:[color=blue]
> "ll" <barn104_1999@yahoo.com> wrote in message
> news:1149522166.647303.109090@j55g2000cwa.googlegr oups.com...[color=green]
> > 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.
> >[/color]
> 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:
>[/color]
Ste> JustSelect = /*2
8432953204368616C6D657273*/[color=blue]
> {
> one : function( form )
> {
> for( var i=0, len=form.elements.length; i<len; i++ )
> if( (el=form.elements[i]).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[i]).type=='select-one' && el!=selElem )
> el.selectedIndex = 0;
> }
> };
>
> then after your form is rendered, add:
>
> JustSelect.one( document.forms.myForm );[/color] | | | | re: Drop Down Limit?
ll wrote:[color=blue]
> 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?[/color]
Anywhere below the form, so it's not called until the form exists.
No changes are needed to the HTML. | | | | re: Drop Down Limit?
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/genform.pl?my.email@doman.com">
----------
Thanks again,
Louis
Stephen Chalmers wrote:[color=blue]
> ll wrote:[color=green]
> > 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?[/color]
>
> Anywhere below the form, so it's not called until the form exists.
> No changes are needed to the HTML.[/color] | | | | re: Drop Down Limit?
"ll" <barn104_1999@yahoo.com> wrote in message
news:1149603353.405598.105480@y43g2000cwc.googlegr oups.com...[color=blue]
> 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:
>[/color]
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). |  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,392 network members.
|