Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Newbie help with test script.

    Hello to all, ASP coder here battling with Javascript. Have been given the following code to try and get working, but am tearing my hair out at the moment.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
     <title>Multiple-Select Dropdown List Example by brokenfish</title>  
     <style type="text/css">  
     /* Specify the styles of selected/unselected items. */ 
     .normal 
     { 
     background: #FFF; 
     } 
     .highlight 
     { 
     background: #CCC; 
     } 
     </style>  
     <script type="text/javascript">
     <!-- 
     /* Multiple-Select Dropdown List Example by brokenfish */ 
     var list = new Array(); 
     
     function toggleOption(value) 
     { 
     	if (value == '-') return; 
      	var notInList = true; 
     	var selectBox = document.getElementById('selectbox'); 
     	// Change 'selectbox' to whatever ID you give your <select>. 
     	var items = selectBox.options;
    
     	for (var i = 0; i < selectBox.length; i++) 
     	{
    	 	alert('element = ' + selectBox.options[i]);
     		if (items[i] == value) 
     		{ 
     			list.splice(i, 1); 
     			notInList = false;
     			items[selectBox.selectedIndex].className = 'normal'; 
     			// Change 'normal' to whatever class you want unselected items to use. 
     		} 
     	} 
     	if (notInList) 
     	{ 
     		list.splice(list.length - 1, 0, value); 
     		items[selectBox.selectedIndex].className = 'highlight'; 
     		// Change 'highlight' to whatever class you want selected items to use. 
     	} 
     	selectBox.selectedIndex = 0; 
     } 
     
     function listSelected() 
     { 
     	if (list.length == 0) alert('No Items Selected'); 
     	else  		alert('Selected Items: ' + list.join(', ')); 
     } 
     //-->
     </script> 
     </head> 
     
     <body> 
     <select name="example" id="selectbox" onchange="toggleOption(this.value);">  
     	<option value="-">Select Items Below</option>  
     	<option value="This">This</option>  
     	<option value="That">That</option>  
     	<!-- Add or remove any of these options. --> 
     </select> 
     <input type="button" value="List Selected" onclick="listSelected();" /> 
     </body> 
     </html>
    It would appear l am not getting the options through to the toggleoption function, from the select tag list in the html. Not sure how to fix this at all, as am completely new to java.

    Thanks in advance, l am having a bad hair day

  • #2
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Disregard, sorted after a bit more effort

    See next thread


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •