469,275 Members | 1,850 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Drop Down Limit?

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

Jun 5 '06 #1
5 1524

"ll" <ba**********@yahoo.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
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[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 );
Jun 5 '06 #2
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 Chalmers wrote:
"ll" <ba**********@yahoo.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
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:

Ste> JustSelect = /*2
8432953204368616C6D657273*/ {
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 );


Jun 5 '06 #3

ll wrote:
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.

Jun 5 '06 #4
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/ge*****************@doman.com">
----------

Thanks again,
Louis



Stephen Chalmers wrote:
ll wrote:
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.


Jun 6 '06 #5

"ll" <ba**********@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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).
Jun 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ian Oldbury | last post: by
1 post views Thread by Hardy Wang | last post: by
7 posts views Thread by callawayglfr | last post: by
5 posts views Thread by brino | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.