473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1661

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
3
by: Darren | last post by:
Please Help Me!! I've created a typical <form> and a <select> element. The options are created dynamically from my access database (using asp). There are about 70 options, and when you click...
4
by: Ian Oldbury | last post by:
Hi all, i'm trying to define the number of items that are shown at a time on a dropdownlist. Ideally i'd like to do this within the css class if possible. How is this done?? This the...
1
by: Hardy Wang | last post by:
Hi all, I have a drop down list with some items, and one of the item contains very long text. I want to limit the width of the drop down itself, but when I click down arrow to pull down the...
5
by: | last post by:
Hi, I'm not sure if what I'm trying to do is possible and there is a limit to my CSS knowledge. I'm trying to generate a CSS drop-down menu from a <li> that has been replaced by an image. The...
7
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
5
by: brino | last post by:
hi all ! i have a drop down list in a form. the users of the data base are typing text in there instead of selecting from the list. how can i make it so they cannot type text and only select...
22
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
2
by: axapta | last post by:
Hi Group, How can I limit a second drop-down list box based on a selected value in the first drop down list box. Using vb.net Regards
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.