selecting all items from select box

Discussion in 'C#' started by akpaga, May 1, 2008.

  1. #1
    i have a select box that gets populated from a table in the database.
    it contains names of the customers.
    i want a check box or a radio button which when checked selects all the items (names) in the select box.

    thanks in advance
     
    akpaga, May 1, 2008 IP
  2. dgxshiny

    dgxshiny Greenhorn

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    23
    #2
    Here is a javascript function that will do just that.

    function SetAllCheckBoxes(FormName, FieldName, CheckValue)
    {
    	if(!document.forms[FormName])
    		return;
    	var objCheckBoxes = document.forms[FormName].elements[FieldName];
    	if(!objCheckBoxes)
    		return;
    	var countCheckBoxes = objCheckBoxes.length;
    	if(!countCheckBoxes)
    		objCheckBoxes.checked = CheckValue;
    	else
    		// set the check value for all check boxes
    		for(var i = 0; i < countCheckBoxes; i++)
    	
    Code (markup):
     
    dgxshiny, May 1, 2008 IP
  3. dgxshiny

    dgxshiny Greenhorn

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    23
    #3
    }
    Code (markup):
    forgot the }
     
    dgxshiny, May 1, 2008 IP
  4. akpaga

    akpaga Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for your reply dgxshiny

    but that cose is to select all check boxes but what i want is to select items in

    select box. please clarify me if i am wrong.
     
    akpaga, May 1, 2008 IP
  5. dgxshiny

    dgxshiny Greenhorn

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    23
    #5
    Sorry, I was thinking checkbox.

    Try this:

     
    dgxshiny, May 2, 2008 IP
  6. akpaga

    akpaga Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thank you very much
     
    akpaga, May 5, 2008 IP