hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Javascript Problem
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Javascript Problem

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-14-2003, 09:16 AM
X-TechMedia X-TechMedia is offline
Junior Guru
 
Join Date: Nov 2002
Location: United Kingdom
Posts: 247
Unhappy

Javascript Problem


I have a series of checkboxes and multiple select lists, that are used to choose which mailing lists to subscribe to.

The checkboxes are called mail[1], mail[2] etc
and the select boxes sel[1], sel[2] etc

I want it so that when i click on mail[1] it selects all the options in sel[1].

its called by onclick="DoAll('n')" (where n is the number, 1,2 etc)

Does anyone know why this isnt working?

Code:
function DoAll(id) {
if (document.action.mail[id].selected==true) {
	for(var i=0;i<document.action.sel[id].length;i++) {
		document.action.sel[i].selected=true;
	}
}

if (document.action.mail[id].selected==false) {
	for(var i=0;i<document.action.sel[id].length;i++) {
		document.action.sel[i].selected=false;
	}
}
}


Last edited by X-TechMedia; 02-14-2003 at 10:10 AM.
Reply With Quote


Sponsored Links
  #2  
Old 02-14-2003, 10:27 AM
sasha sasha is offline
Hail Eris !
 
Join Date: Oct 2002
Location: Canada
Posts: 3,100
i think you might need to refer to options as:
document.action.sel[id].options[i]

Reply With Quote
  #3  
Old 02-14-2003, 10:33 AM
Rich2k Rich2k is offline
Web Hosting Master
 
Join Date: May 2002
Location: UK
Posts: 2,994
I wouldn't do it like that. Firstly all of your form elements should be in a form or they may not work in Netscape.

Code:
function DoAll(id) {
if (document.forms.formname.checkboxname[id].checked == true) {
	for(var i=0;i<document.forms.formname.selectname[id].length;i++) {
		document.forms.formname.selectname[id].optionname.selected = true;
	}
}
}
and then don't call it with DoAll['n'] but DoAll[n] as it's a numeric value.

obviously you need to replace the element and form names in the above

Remember for checkboxes you have to test for checked NOT selected

(Note: I haven't tested this so it may have errors)

Reply With Quote
Sponsored Links
  #4  
Old 02-14-2003, 10:39 AM
sasha sasha is offline
Hail Eris !
 
Join Date: Oct 2002
Location: Canada
Posts: 3,100
... or like this




function DoAll(id) {
bl = document.action.sel[id] ;
if (document.action.mail[id].selected==true) {
for(var i=0;i<bl.options.length;i++) {
bl.options[i].selected=true;
}
}

Reply With Quote
  #5  
Old 02-14-2003, 11:56 AM
X-TechMedia X-TechMedia is offline
Junior Guru
 
Join Date: Nov 2002
Location: United Kingdom
Posts: 247
Thanks people, i got it sorted in the end!

in case your intrested:

Code:
if (document.action.elements['mail['+ id +']'].checked==true) {
		for(var i=0;i<document.action.elements['sel['+ id +']'].length;i++) {
			document.action.elements['sel['+ id +']'].options[i].selected=true;
		}
	}
	
	if (document.action.elements['mail['+ id +']'].checked==false) {
		for(var i=0;i<document.action.elements['sel['+ id +']'].length;i++) {
			document.action.elements['sel['+ id +']'].options[i].selected=false;
		}
	}

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Outbound Spam Causing Sleepless Nights? Blog 2013-05-13 09:52:21
Facebook's Recently Acquired Mobile App Platform Parse Launches Web Hosting for Developers Web Hosting News 2013-05-08 10:49:17
How To Deliver Products Customers Will Pay For with David Koston - HostingCon 2012 Web Hosting News 2012-07-18 10:46:16
Microsoft Launches First Beta of Microsoft WebMatrix 2.0 Web Hosting News 2011-09-26 15:43:24
The Lesson of the Ten, with Jeff Hardy Web Hosting News 2011-08-08 22:12:01


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?