Solved

Question on drop down list

Posted on 2002-07-02
15
154 Views
Last Modified: 2010-04-09
How can I implement Disallow First to make sure the first item in the drop down list is never selected?
0
Comment
Question by:alexandram
  • 4
  • 3
  • 3
  • +4
15 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7125533
Try:

<select onChange="if (this.selectedIndex==0) {this.options[1].selected=true; this.selectedIndex=1;}">
<option> first option</option>
<option selected>second option</option>
<option> Third option</option>
<option> Fourth option</option>
<option> fifth option</option>
</select>

Cd&
0
 
LVL 30

Expert Comment

by:third
ID: 7125600
if you don't want it to get selected, then why put it as an option in the selectbox?
0
 
LVL 18

Accepted Solution

by:
bruno earned 100 total points
ID: 7125753
<select name="mySelect">
<option value="">-------- select one --------</option>
<option value="2">second option</option>
<option value="3"> Third option</option>
<option value="4"> Fourth option</option>
<option value="5"> fifth option</option>
</select>


use javascript on form submit to make sure that the "mySelect" HAS a value...if not, pop up an alert box to tell them that they have to select something...


<script type="text/javascript" language="JavaScript">
function fnVerify(theForm)
{
     if(document.myForm.mySelect.value == "")
          {
          alert("Please make a selection");
          document.myForm.mySelect.focus();
          return false;
          }                    
     return true;
     }    

</script>




BRUNO
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7125857
not the answer but you could color it differently !!

<option style="background-color:#ffffff; color: #33333;"> not selectable </option>


;)
0
 
LVL 18

Expert Comment

by:bruno
ID: 7125889
Looking forward to your feedback alexandram...

I have a good feeling that my previous comment was very close to the heart of the solution, and am interested to find out if i was correct.


BRUNO
0
 
LVL 2

Expert Comment

by:fnizet
ID: 7126767
I don't know if Bruno's right, but his solution sounds good.

I usually do the test with CobolDinosaur's function but when the form is submitted, not on the onChange event :

<script type="text/javascript" language="JavaScript">
function fnVerify(theForm)
{
    if(document.myForm.mySelect.selectedIndex == 0)
         {
         alert("Please make a selection");
         document.myForm.mySelect.focus();
         return false;
         }                    
    return true;
}    

</script>
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7126779
Well I don't see where they are asking for validation; just prevention.  If validation is wht is required then Iwould also do it in a function off of the submit, but I think they are just trying to disable the option.

Cd&
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:fnizet
ID: 7126808
Then we agree, CobolDinosaur.
When re-reading the question, I'd say you're probably right.

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7126811
I like this way:

<SELECT name='mySelect' onChange='this.selectedIndex=(this.selectedIndex==0?-1:this.selectedIndex);'>
0
 
LVL 18

Expert Comment

by:bruno
ID: 7126976
I can't imagine WHY a solution like yours would be needed Cd&....WHY even have the first option there?

I know at my previous job our first option was always

<option value="">------select one------</option>


we used it to set the width of the select box, but obviously, it shouldn't be a selection when the form is submitted.  however, it DOES need to be able to show...


I guess we will have to wait and see what alexandram says.



BRUNO
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7127532
<option disabled>disabled</option>

# probably not working for 75% audiance ;-)
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7127544
>>> # probably not working for 75% audiance ;-)
more like 95%  ...  Netscrap 6, opera and moz1.0  AFAIK

Cd&
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7127569
Netscape 6.x, Mozilla 1.x works
opera 5 and 6 works too, but is strange (you can select, but the selection is not activated, for obvious reason:)
Opera 3 and 4 not yet tested ...
0
 
LVL 18

Expert Comment

by:bruno
ID: 7211294
Glad I could help.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7216946
graded the solution which works for any browser, even mosaic 0.9
Great!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now