I want the user to be able to enter some text (a date actually) and click
a
button. The button would cause the field value to be added to a static
list
of dates.
I also need to be able to delete from that list as well. So I guess a
list
box would be the element of choice.
By 'list box' I guess you mean a select element.
I would then process those dates using an array in php.
In order to send them to the server, you'll need to make the select a
'select-multiple' and then make them all selected before sending the
form (or put them into a hidden input).
Any ideas or links on how to do this?
See below for an example - remember that a select element must always
have at least one option, otherwise it is invalid HTML. Also, you can
add value as well as text when creating the option - there are lots of
examples in the archives of how to add options using new Option.
<script type="text/javascript">
function addOption(sel, txt){
if (sel.options[0] && sel.options[0].text == ''){
sel.removeChild(sel.options[0]);
}
sel.options[sel.options.length] = new Option(txt);
}
function deleteOption(sel){
if (sel.selectedIndex >=0){
var selectedOption = sel.options[sel.selectedIndex];
sel.removeChild(selectedOption);
}
if (sel.options.length == 0){
addOption(sel, '');
}
}
</script>
<form action=""><div>
<input type="text" name="textDate">
<input type="button" value="Add"
onclick="addOption(this.form.xx, this.form.textDate.value);">
<br>
<select name="xx" size="10" style="width: 8em;">
<option>
</select>
<input type="button" value="Remove selected"
onclick="deleteOption(this.form.xx);
">
</div>
</form>
Rob