...

View Full Version : Newbie help with test script.



Salient
07-12-2005, 05:49 AM
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.



<!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 :(

Salient
07-12-2005, 08:38 AM
Disregard, sorted after a bit more effort :thumbsup:

See next thread :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum