HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 23rd, 2004, 08:07 AM
Beelzibub Beelzibub is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 42 Beelzibub User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 25 sec
Reputation Power: 6
Assigning various list boxes to the same code

if (document.form1.select_class_year3.options[0].selected )
{
for (i = 1; i<=document.form1.select_class_year3.length; i++ )
{
if ( document.form1.select_class_year3.options[i].selected )
{
alert("You cannot select 'All' and another option. Please Unselect the rest.");
return false;
}
}
}
return true;


I am having around 15 list boxes in my page. I need to use the above code for each. I am using the above code in the onChange event of each list box, so that it wouldn’t allow me to choose two options if the option all as represented by the code options[0] above. I want to make the above code generic to all the listboxes. The above code has a specific list box ‘select_class_year3’. I don’t want to write the same code for every list box. Is there a way I could get all the names of the list boxes in a variable and loop in one by one so that the above code would apply to all list boxes ? Does Java Script allow such kind of coding?

Thank You.

Reply With Quote
  #2  
Old February 23rd, 2004, 09:11 AM
Yeruhn's Avatar
Yeruhn Yeruhn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Netherlands
Posts: 428 Yeruhn User rank is Sergeant (500 - 2000 Reputation Level)Yeruhn User rank is Sergeant (500 - 2000 Reputation Level)Yeruhn User rank is Sergeant (500 - 2000 Reputation Level)Yeruhn User rank is Sergeant (500 - 2000 Reputation Level)Yeruhn User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 16 h 35 m 27 sec
Reputation Power: 10
try 'this':

function check(obj) {
if (obj.options[0].selected) {
....
}
}

call with: <select onchange='check(this)'>

Reply With Quote
  #3  
Old February 24th, 2004, 12:41 PM
Beelzibub Beelzibub is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 42 Beelzibub User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 25 sec
Reputation Power: 6
Thanks a lot.

Quote:
Originally Posted by Yeruhn
try 'this':

function check(obj) {
if (obj.options[0].selected) {
....
}
}

call with: <select onchange='check(this)'>

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Assigning various list boxes to the same code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT