473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Combo box - adding bells and whistles?

I'd be very grateful if anyone could help me with this. From my limited
knowledge of Javascript I don't think it is possible, but I'll punt anyway.
I downloaded and very slightly adapted this guy's Javascript "combo box" -
http://sandy.mcarthur.org/javascript/select/select.html. It allows my users
(when I get some!) to select from a list of preexisting options and also to
add a new one by clicking on "add new". Essentially it's a select control
that turns into an input control when the "add new" option is clicked. (I
think that's how it works.) There may be several of these on a page. What
I would like is for the user's added option to be included on all the other
select controls.

The original page is of necessity behind a login
(http://www.listyblue.com/config.php), so I've cut and pasted the HTML for
it here.

The Javascript is at the bottom.

+e

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<title>Change item groups and reminder intervals</title>

<!-- This page uses Javascript to populate a "combo box" style select
input, i.e. it allows the user to edit it as well as select from existing
options -->
<!-- This script is "borrowed" from a Mr Sandy McArthur, whose original
implementation is to be found here -
http://sandy.mcarthur.org/javascript/select/select.html -->

<style type="text/css">
@import "css.css";

</style>

<script type="text/javascript" src="select.js"></script>

</head>
<body>

<div id="topper">
<img class="logo" src="logo.gif" alt="logo" />
<h1><span class="hidden">listyblue </span>the list manager</h1>
</div<!-- topper -->

<h1>Barfkins McDoodle's items</h1><div id="right"><img class="fixedimage"
src="/userimages/barfkins.gif" alt="mascot image" /><div class="long"
style="clear:both"></div></div><div id="list"><form
action="configprocess.php" method="post"><table><tr><th>Item</th><th
>Group</th><th>Reminder Interval</th></tr>
<tr>
<td><input type="checkbox" checked="checked" name="new[]" value="Beer"
/>Beer</td>

<td><script type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter" value="Alcohol"
selected="selected">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select');</script></td>

<noscript><td><input name="newgroup[]" type="text" maxlength = "24"
value="Alcohol" /></td></noscript>

<td><input class="threer" name="newremint[]" type="text" value = "0"
maxlength = "3" /></td>

</tr>

<tr><td><input type="checkbox" checked="checked" name="new[]" value="Wine"
/>Wine</td><td><script type="text/javascript">document.write( '<select
class="editable keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol" selected="selected">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Alcohol" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Milk" />Milk</td><td><script type="text/javascript">document.write(
'<select class="editable keepSorted" name="newgroup[]"><option
class="righter" value="Alcohol">Alcohol</option><option class="righter"
value="Dairy" selected="selected">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Dairy" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Cheese" />Cheese</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter" value="Dairy"
selected="selected">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Dairy" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Juice" />Juice</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter" value="Fruit"
selected="selected">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Fruit" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Fruit" />Fruit</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter" value="Fruit"
selected="selected">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Fruit" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="i want one of those" />i want one of those</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter" value="General"
selected="selected">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="General" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="New item 2" />New item 2</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter" value="General"
selected="selected">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="General" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="New item 3" />New item 3</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter" value="General"
selected="selected">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="General" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Mince" />Mince</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter" value="Meat"
selected="selected">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Meat" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Beef" />Beef</td><td><script type="text/javascript">document.write(
'<select class="editable keepSorted" name="newgroup[]"><option
class="righter" value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter" value="Meat"
selected="selected">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Meat" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Cereals" />Cereals</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter" value="Staples"
selected="selected">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Staples" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Croissants" />Croissants</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter" value="Staples"
selected="selected">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Staples" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Shampoo" />Shampoo</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Washing powder" />Washing powder</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Fabric conditioner" />Fabric conditioner</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Washingup liquid" />Washingup liquid</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Scalextric" />Scalextric</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter" value="Toys"
selected="selected">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toys" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="BMX" />BMX</td><td><script type="text/javascript">document.write(
'<select class="editable keepSorted" name="newgroup[]"><option
class="righter" value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter" value="Toys"
selected="selected">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toys" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Tool set" />Tool set</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter" value="Toys"
selected="selected">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toys" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Vegetables" />Vegetables</td><td><script
type="text/javascript">document.write( '<select class="editable keepSorted"
name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter" value="Vegetables"
selected="selected">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Vegetables" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr></table><div class="buttonhole"><div class="inline"><input
type="submit" name="submit" value="Change items" class="bigbtn"
/></div></div<!-- buttonhole --></form></div<!-- list -->

<div id="footer">
<hr />
<h3><a href="http://www.listyblue.com/main.php">www.listyblue.com</a></h3>
</div<!-- footer -->
</body>
</html>
// Editable Select Boxes 0.5.2//// Copyright 2005 Sandy McArthur:
http://Sandy.McArthur.org///// You are free to use this code however you
please as long as the// above copyright is preserved. It would be nice if
you sent me// any bug fixes or improvements you make.//
var EditableSelect = { /** The value used to indicate an option is
the "edit" value. */ "editValue": "editit", /** The text used when
creating an edit option for a select box. */ "editText": "*add new*",
/** The text used when creating an edit option for a select box. */
"editClass": "activateEdit", /** * Finds all select elements and
if they have the "editable" CSS class then * it makes that select be
editable. */ "activateAll": function () { var selects =
document.getElementsByTagName("select"); for (var i=0; i <
selects.length; i++) { var select = selects[i]; if
(EditableSelect.hasClass(select, "editable")) {
EditableSelect.activate(select); } } }, /**
Makes the select element editable. */ "activate": function (select)
{ if (!EditableSelect.selectHasEditOption(select)) {
EditableSelect.selectAddEditOption(select); }
select.oldSelection = select.options.selectedIndex;
EditableSelect.addEvent(select, "change", EditableSelect.selectOnChage);
EditableSelect.addClass(select, "editable"); }, /** Does the
select box have an edit option. */ "selectHasEditOption": function
(select) { var options = select.options; for (var i=0; i <
options.length; i++) { if (options.item(i).value ==
EditableSelect.editValue) { return
} } return false; }, /** Add an edit
option to the select box. */ "selectAddEditOption": function (select)
{ var option = document.createElement("option"); option.value
= EditableSelect.editValue; option.text = EditableSelect.editText;
option.className = EditableSelect.editClass;
EditableSelect.selectAddOption(select, option, 0); }, /** *
Add an option to the select box at specified postion. * "index" is
optionial, if left undefined then the end is assumed. */
"selectAddOption": function (select, option, index) { if
(select.options.add) { if (typeof index == "undefined")
{ select.options.add(option); } else
{ select.options.add(option,index); } }
else { if (typeof index == "undefined") {
select.insertBefore(option); } else { var before =
select.options.item(index); select.insertBefore(option,
before); } } }, /** * Event handler for
select box. If the edit option is selected it * switches to the edit
input field. */ "selectOnChage": function (evt) { var select =
this; if (evt.srcElement) select = evt.srcElement; // For IE
if (select.value == EditableSelect.editValue) { var input =
document.createElement("input"); input.type = "text";
input.value = select.options.item(select.oldSelection).value;
input.className = select.className; input.name = select.name;
input.selectOnChange = select.onchange;
EditableSelect.addEvent(input, "blur", EditableSelect.inputOnBlur);
EditableSelect.addEvent(input, "keypress", EditableSelect.inputOnKeyPress);
var oldOptions = []; for (var i=0; i < select.options.length;
i++) { var o = select.options.item(i); var sn
= o; var oo = EditableSelect.serializeOption(o);
oldOptions[oldOptions.length] = oo; }
select.parentNode.replaceChild(input, select); input.focus();
input.select(); input.oldOptions =
} else { select.oldSelection =
select.options.selectedIndex; } }, /** * Event handler
for the input field when the field has lost focus. * This rebuilds the
select box possibly adding a new option for what * the user typed.
*/ "inputOnBlur": function (evt) { var input = this; if
(evt.srcElement) input = evt.srcElement; // For IE var keepSorted =
EditableSelect.hasClass(input, "keepSorted"); var value =
input.value; var select = document.createElement("select");
select.className = input.className; select.name = input.name;
select.onchange = input.selectOnChange; var selectedIndex
= -1; var optionIndex = 0; var oldOptions = input.oldOptions;
var newOption = {"text": value, "value": value }; for (var i=0; i <
oldOptions.length; i++) { var n = oldOptions[i];
if (newOption != null && EditableSelect.inputCompare(n,
newOption) == 0) { newOption = null; } else if
(keepSorted && newOption != null && EditableSelect.inputCompare(n,
newOption) 0) { EditableSelect.selectAddOption(select,
EditableSelect.deserializeOption(newOption));
selectedIndex = optionIndex; optionIndex++;
newOption = null; } if (selectedIndex
== -1 && n.value == value) { selectedIndex =
; } var opt =
EditableSelect.deserializeOption(n);
EditableSelect.selectAddOption(select, opt); optionIndex++;
input.oldOptions[i] = null; } if (newOption != null)
{ var opt = EditableSelect.deserializeOption(newOption);
EditableSelect.selectAddOption(select, opt);
select.options.selectedIndex = optionIndex; select.oldSelection =
select.options.selectedIndex; } else {
select.options.selectedIndex = selectedIndex; select.oldSelection
= select.options.selectedIndex; }
EditableSelect.activate(select);
input.parentNode.replaceChild(select, input); select.blur();
if (select.onchange) select.onchange(); }, "inputCompare":
function (x, y) { if (x.value == EditableSelect.editValue && y.value
== EditableSelect.editValue) { return 0; } if
(x.value == EditableSelect.editValue) { return -1; }
if (y.value == EditableSelect.editValue) { return 1; }
var xText = x.text ? x.text.toUpperCase() : ""; var yText = y.text ?
y.text.toUpperCase() : ""; if (xText < yText) {
return -1; } else if (xText == yText) { return
} else { return 1; } }, /** Intercept enter
key presses to prevent form submit but still update the field. */
"inputOnKeyPress": function (evt) { var e; if (evt)
{ e = evt; } else if (window.event) { e =
window.event; } else { throw
"EditableSelect.inputOnKeyPress: Unable to find the event."; }
if (e.keyCode == 13) { if (e.currentTarget) {
e.currentTarget.blur(); return false; // Prevent form
} else if (e.srcElement) { e.srcElement.blur();
return false; // Prevent form submit } else {
throw "EditableSelect.inputOnKeyPress: Unknown event
} } return true; }, /** Convert an
option element to a form that can be attached to the input element. */
"serializeOption": function (option) { var ser = {}; if
(option.text) ser.text = option.text; if (option.value) ser.value =
option.value; if (option.disabled) ser.disabled = option.disabled;
if (option.label) ser.label = option.label; if (option.className)
ser.className = option.className; if (option.title) ser.title =
option.title; if (option.id) ser.id = option.id; return
; }, /** Reverse the serializeOption function into an option
element. */ "deserializeOption": function (ser) { var option =
document.createElement("option"); if (ser.text) option.text =
ser.text; if (ser.value) { option.value =
ue; } else if (ser.text) { option.value =
t; } if (ser.disabled) option.disabled = ser.disabled;
if (ser.label) option.label = ser.label; if (ser.className)
option.className = ser.className; if (ser.title) option.title =
ser.value; if (ser.id) option.id = ser.id; return
ion; }, /** Does this element have the CSS class? */
"hasClass": function (element, clazz) { var regex = new
RegExp('\\b'+clazz+'\\b'); return
ex.test(element.className); }, /** Append the CSS class to the
element if it doesn't exist. */ "addClass": function (element, clazz)
{ if (!EditableSelect.hasClass(element, clazz)) {
element.className = element.className + " " + clazz; } },
/** Remove the CSS class from the element if it exist. */ "removeClass":
function (element, clazz) { if (EditableSelect.hasClass(element,
clazz)) { element.className = element.className.replace(clazz,
""); } }, // From:
http://www.scottandrew.com/weblog/articles/cbs-events /** Add an event in
a cross browser way. */ "addEvent": function (obj, evType, fn,
useCapture) { if (obj.addEventListener){
obj.addEventListener(evType, fn, useCapture); return
} else if (obj.attachEvent){ var r =
obj.attachEvent("on"+evType, fn); return r; } else
{ alert("Handler could not be attached"); } },
/** Remove an event in a cross browser way. */ "removeEvent": function
(obj, evType, fn, useCapture){ if
(obj.removeEventListener){ obj.removeEventListener(evType, fn,
useCapture); return true; } else if
(obj.detachEvent){ var r = obj.detachEvent("on"+evType, fn);
return r; } else { alert("Handler could not be
"); } }}
EditableSelect.addEvent(window, 'load', EditableSelect.activateAll);
Dec 1 '06 #1
1 2436
Bump

"The Eclectic Electric" <no****@spamispoo.spamwrote in message
news:C7****************@newsfe2-gui.ntli.net...
I'd be very grateful if anyone could help me with this. From my limited
knowledge of Javascript I don't think it is possible, but I'll punt
anyway. I downloaded and very slightly adapted this guy's Javascript
"combo box" - http://sandy.mcarthur.org/javascript/select/select.html. It
allows my users (when I get some!) to select from a list of preexisting
options and also to add a new one by clicking on "add new". Essentially
it's a select control that turns into an input control when the "add new"
option is clicked. (I think that's how it works.) There may be several
of these on a page. What I would like is for the user's added option to
be included on all the other select controls.

The original page is of necessity behind a login
(http://www.listyblue.com/config.php), so I've cut and pasted the HTML for
it here.

The Javascript is at the bottom.

+e

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<title>Change item groups and reminder intervals</title>

<!-- This page uses Javascript to populate a "combo box" style select
input, i.e. it allows the user to edit it as well as select from existing
options -->
<!-- This script is "borrowed" from a Mr Sandy McArthur, whose original
implementation is to be found here -
http://sandy.mcarthur.org/javascript/select/select.html -->

<style type="text/css">
@import "css.css";

</style>

<script type="text/javascript" src="select.js"></script>

</head>
<body>

<div id="topper">
<img class="logo" src="logo.gif" alt="logo" />
<h1><span class="hidden">listyblue </span>the list manager</h1>
</div<!-- topper -->

<h1>Barfkins McDoodle's items</h1><div id="right"><img class="fixedimage"
src="/userimages/barfkins.gif" alt="mascot image" /><div class="long"
style="clear:both"></div></div><div id="list"><form
action="configprocess.php" method="post"><table><tr><th>Item</th><th
Group</th><th>Reminder Interval</th></tr>

<tr>
<td><input type="checkbox" checked="checked" name="new[]" value="Beer"
/>Beer</td>

<td><script type="text/javascript">document.write( '<select
class="editable keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol" selected="selected">Alcohol</option><option
class="righter" value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select');</script></td>

<noscript><td><input name="newgroup[]" type="text" maxlength = "24"
value="Alcohol" /></td></noscript>

<td><input class="threer" name="newremint[]" type="text" value = "0"
maxlength = "3" /></td>

</tr>

<tr><td><input type="checkbox" checked="checked" name="new[]" value="Wine"
/>Wine</td><td><script type="text/javascript">document.write( '<select
class="editable keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol" selected="selected">Alcohol</option><option
class="righter" value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Alcohol" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Milk" />Milk</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter" value="Dairy"
selected="selected">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Dairy" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Cheese" />Cheese</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter" value="Dairy"
selected="selected">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Dairy" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Juice" />Juice</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter" value="Fruit"
selected="selected">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Fruit" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Fruit" />Fruit</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter" value="Fruit"
selected="selected">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Fruit" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="i want one of those" />i want one of those</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter" value="General"
selected="selected">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="General" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="New item 2" />New item 2</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter" value="General"
selected="selected">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="General" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="New item 3" />New item 3</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter" value="General"
selected="selected">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="General" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Mince" />Mince</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter" value="Meat"
selected="selected">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Meat" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Beef" />Beef</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter" value="Meat"
selected="selected">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Meat" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Cereals" />Cereals</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter" value="Staples"
selected="selected">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Staples" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Croissants" />Croissants</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter" value="Staples"
selected="selected">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Staples" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Shampoo" />Shampoo</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Washing powder" />Washing powder</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Fabric conditioner" />Fabric conditioner</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Washingup liquid" />Washingup liquid</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter" value="Toiletries"
selected="selected">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toiletries" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Scalextric" />Scalextric</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter" value="Toys"
selected="selected">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toys" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="BMX" />BMX</td><td><script type="text/javascript">document.write(
'<select class="editable keepSorted" name="newgroup[]"><option
class="righter" value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter" value="Toys"
selected="selected">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toys" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Tool set" />Tool set</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter" value="Toys"
selected="selected">Toys</option><option class="righter"
value="Vegetables">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Toys" /></td></noscript><td><input class="threer"
name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr><tr><td><input type="checkbox" checked="checked" name="new[]"
value="Vegetables" />Vegetables</td><td><script
type="text/javascript">document.write( '<select class="editable
keepSorted" name="newgroup[]"><option class="righter"
value="Alcohol">Alcohol</option><option class="righter"
value="Dairy">Dairy</option><option class="righter"
value="Fruit">Fruit</option><option class="righter"
value="General">General</option><option class="righter"
value="Meat">Meat</option><option class="righter"
value="Staples">Staples</option><option class="righter"
value="Toiletries">Toiletries</option><option class="righter"
value="Toys">Toys</option><option class="righter" value="Vegetables"
selected="selected">Vegetables</option><option class="righter"
value="General">General</option></select>
');</script></td><noscript><td><input name="newgroup[]" type="text"
maxlength = "24" value="Vegetables" /></td></noscript><td><input
class="threer" name="newremint[]" type="text" value = "0" maxlength = "3"
/></td></tr></table><div class="buttonhole"><div class="inline"><input
type="submit" name="submit" value="Change items" class="bigbtn"
/></div></div<!-- buttonhole --></form></div<!-- list -->

<div id="footer">
<hr />
<h3><a href="http://www.listyblue.com/main.php">www.listyblue.com</a></h3>
</div<!-- footer -->
</body>
</html>
// Editable Select Boxes 0.5.2//// Copyright 2005 Sandy McArthur:
http://Sandy.McArthur.org///// You are free to use this code however you
please as long as the// above copyright is preserved. It would be nice if
you sent me// any bug fixes or improvements you make.//
var EditableSelect = { /** The value used to indicate an option is
the "edit" value. */ "editValue": "editit", /** The text used
when creating an edit option for a select box. */ "editText": "*add
new*", /** The text used when creating an edit option for a select box. */
"editClass": "activateEdit", /** * Finds all select elements
and if they have the "editable" CSS class then * it makes that select
be editable. */ "activateAll": function () { var selects =
document.getElementsByTagName("select"); for (var i=0; i <
selects.length; i++) { var select = selects[i]; if
(EditableSelect.hasClass(select, "editable")) {
EditableSelect.activate(select); } } }, /**
Makes the select element editable. */ "activate": function (select)
{ if (!EditableSelect.selectHasEditOption(select)) {
EditableSelect.selectAddEditOption(select); } select.oldSelection =
select.options.selectedIndex; EditableSelect.addEvent(select, "change",
EditableSelect.selectOnChage); EditableSelect.addClass(select,
"editable"); }, /** Does the select box have an edit option. */
"selectHasEditOption": function (select) { var options =
select.options; for (var i=0; i < options.length; i++)
{ if (options.item(i).value == EditableSelect.editValue)
{ return } } return false; }, /**
Add an edit option to the select box. */ "selectAddEditOption":
function (select) { var option = document.createElement("option");
option.value = EditableSelect.editValue; option.text =
EditableSelect.editText; option.className = EditableSelect.editClass;
EditableSelect.selectAddOption(select, option, 0); }, /** *
Add an option to the select box at specified postion. * "index" is
optionial, if left undefined then the end is assumed. */
"selectAddOption": function (select, option, index) { if
(select.options.add) { if (typeof index == "undefined")
{ select.options.add(option); } else
{ select.options.add(option,index); } }
else { if (typeof index == "undefined") {
select.insertBefore(option); } else { var before
= select.options.item(index); select.insertBefore(option,
before); } } }, /** * Event handler for
select box. If the edit option is selected it * switches to the edit
input field. */ "selectOnChage": function (evt) { var select
= this; if (evt.srcElement) select = evt.srcElement; // For IE if
(select.value == EditableSelect.editValue) { var input =
document.createElement("input"); input.type = "text";
input.value = select.options.item(select.oldSelection).value;
input.className = select.className; input.name = select.name;
input.selectOnChange = select.onchange; EditableSelect.addEvent(input,
"blur", EditableSelect.inputOnBlur); EditableSelect.addEvent(input,
"keypress", EditableSelect.inputOnKeyPress); var oldOptions = [];
for (var i=0; i < select.options.length; i++) { var o =
select.options.item(i); var sn = o; var oo =
EditableSelect.serializeOption(o); oldOptions[oldOptions.length] =
} select.parentNode.replaceChild(input, select);
input.focus(); input.select(); input.oldOptions = } else
{ select.oldSelection =
ect.options.selectedIndex; } }, /** * Event handler
for the input field when the field has lost focus. * This rebuilds the
select box possibly adding a new option for what * the user typed. */
"inputOnBlur": function (evt) { var input = this; if
(evt.srcElement) input = evt.srcElement; // For IE var keepSorted =
EditableSelect.hasClass(input, "keepSorted"); var value =
input.value; var select = document.createElement("select");
select.className = input.className; select.name = input.name;
select.onchange = input.selectOnChange; var selectedIndex
= -1; var optionIndex = 0; var oldOptions =
input.oldOptions; var newOption = {"text": value, "value": value };
for (var i=0; i < oldOptions.length; i++) { var n =
oldOptions[i];
if (newOption != null && EditableSelect.inputCompare(n,
newOption) == 0) { newOption = null; } else if
(keepSorted && newOption != null && EditableSelect.inputCompare(n,
newOption) 0) { EditableSelect.selectAddOption(select,
EditableSelect.deserializeOption(newOption)); selectedIndex = optionIndex;
optionIndex++; newOption = null; } if
(selectedIndex == -1 && n.value == value) { selectedIndex =
; } var opt =
EditableSelect.deserializeOption(n);
EditableSelect.selectAddOption(select, opt); optionIndex++;
input.oldOptions[i] = null; } if (newOption != null)
{ var opt = EditableSelect.deserializeOption(newOption);
EditableSelect.selectAddOption(select, opt); select.options.selectedIndex
= optionIndex; select.oldSelection =
select.options.selectedIndex; } else { select.options.selectedIndex
= selectedIndex; select.oldSelection =
select.options.selectedIndex; } EditableSelect.activate(select);
input.parentNode.replaceChild(select, input); select.blur(); if
(select.onchange) select.onchange(); }, "inputCompare": function
(x, y) { if (x.value == EditableSelect.editValue && y.value ==
EditableSelect.editValue) { return 0; } if
(x.value == EditableSelect.editValue) { return -1; } if
(y.value == EditableSelect.editValue) { return 1; } var
xText = x.text ? x.text.toUpperCase() : ""; var yText = y.text ?
y.text.toUpperCase() : ""; if (xText < yText) { return -1; }
else if (xText == yText) { return } else { return
} }, /** Intercept enter key presses to prevent form submit
but still update the field. */ "inputOnKeyPress": function (evt)
{ var e; if (evt) { e = evt; } else if
(window.event) { e = window.event; } else {
throw "EditableSelect.inputOnKeyPress: Unable to find the
; } if (e.keyCode == 13) { if (e.currentTarget) {
e.currentTarget.blur(); return false; // Prevent form }
else if (e.srcElement) { e.srcElement.blur(); return false;
// Prevent form submit } else { throw
"EditableSelect.inputOnKeyPress: Unknown event } } return
true; }, /** Convert an option element to a form that can be
attached to the input element. */ "serializeOption": function (option)
{ var ser = {}; if (option.text) ser.text = option.text;
if (option.value) ser.value = option.value; if (option.disabled)
ser.disabled = option.disabled; if (option.label) ser.label =
option.label; if (option.className) ser.className =
option.className; if (option.title) ser.title = option.title;
if (option.id) ser.id = option.id; return ; }, /**
Reverse the serializeOption function into an option element. */
"deserializeOption": function (ser) { var option =
document.createElement("option"); if (ser.text) option.text =
ser.text; if (ser.value) { option.value = ue; }
else if (ser.text) { option.value = t; } if
(ser.disabled) option.disabled = ser.disabled; if (ser.label) option.label
= ser.label; if (ser.className) option.className = ser.className;
if (ser.title) option.title = ser.value; if (ser.id) option.id =
ser.id; return ion; }, /** Does this element have the CSS
class? */ "hasClass": function (element, clazz) { var regex = new
RegExp('\\b'+clazz+'\\b'); return ex.test(element.className); },
/** Append the CSS class to the element if it doesn't exist. */
"addClass": function (element, clazz) { if
(!EditableSelect.hasClass(element, clazz)) { element.className =
element.className + " " + clazz; } }, /** Remove the CSS class
from the element if it exist. */ "removeClass": function (element,
clazz) { if (EditableSelect.hasClass(element, clazz))
{ element.className = element.className.replace(clazz,
} }, // From:
http://www.scottandrew.com/weblog/articles/cbs-events /** Add an event
in a cross browser way. */ "addEvent": function (obj, evType, fn,
useCapture) { if (obj.addEventListener){
obj.addEventListener(evType, fn, useCapture); return } else if
(obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn);
return r; } else { alert("Handler could not be
attached"); } }, /** Remove an event in a cross browser way. */
"removeEvent": function (obj, evType, fn, useCapture){ if
(obj.removeEventListener){ obj.removeEventListener(evType, fn,
useCapture); return true; } else if
(obj.detachEvent){ var r = obj.detachEvent("on"+evType, fn);
return r; } else { alert("Handler could not be
} }}
EditableSelect.addEvent(window, 'load', EditableSelect.activateAll);

Dec 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mal | last post by:
Sorry for repost - system added to another subject for some reason Have tried numerous ideas from the group to solve this one. It is such a simple example that it should be straightforward ! I...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
0
by: JL3574 l | last post by:
i have a datagrid with a combo box added in it's columns . the combobox pulls values from a database in it's dropdownlist fashion. my problem is that when i pick a select on the combo box it...
2
by: Jeff Mason | last post by:
I'm observing some strange behavior when I use a bound combo box in conjunction with the combo's anchor property. I define a form which contains just a textbox and a combo box. The text box is...
2
by: Nikolay Petrov | last post by:
I have asked a question before some time, and a guy responded to it. His answer raised new questions and I replied them back, but still no answer. I need them urgently so I am to post the whole...
6
by: vb | last post by:
Hi, I am new to .Net. I am using a Combo Box in my windows forms. I am adding the items by creating the instances and adding the same to the list. My questions/doubts are: 1. If I have 25 to...
3
by: Sindbaad | last post by:
Hi, I have a databound Combo Box where I'm adding a new value to the database on the Click of the button. I'm able to see the ComboText and it is writing to the database. But when I do a refresh...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
1
by: Josephbupe | last post by:
Sorry, i didn't know exactly what to name my question. What i need is to create a database for storing office items that will include Desktop computers, Laptops, printers, phones, etc. as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.