Robert Bravery wrote:
[...] I want an alert box to apear when a user
selects a certain selection from a selet dropdownbox.
The select box is populated with data from a lookuptable from mysql. I
have assigned the table key to the value of the select box, and the
description column to the text of the select box. The table has one more
column 'closed' which is a int value of eother 1 or 0.
I would like the alert box to apear only when the users selects an option
that has a corresponding value of 1 in the 'closed' column.
Several things come to my mind. In order of preference:
1. Since the "closed" values appear to be forbidden ones, why serve them
in the first place?
2. The `option' element has a `disabled' attribute that can be used.
Disabled options cannot be selected.
<select ...>
...
<option value="2" disabled>bar (closed)</option>
...
</select>
You should test server-side whether a "closed" value was submitted
anyway.
3. Since the `option' element does not have an additional attribute that
can be used reasonably (user-defined attributes require XHTML or are
invalid markup, and unreliable anyway; the `click' event is not widely
supported for the `option' element), you would have to serve additional
script code that identifies a selected option as "closed". Such as:
...
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>
<body ...>
...
<form ...>
...
<script type="text/javascript">
var closed = [0, 1, 0, 0];
</script>
...
<select name="foobar" size="10"
onchange="if (closed[this.selectedIndex-1]) window.alert('...');">
<option value="0" selected>--- Select an option ---</option>
<option value="1">foo (open)</option>
<option value="2">bar (closed)</option>
<option value="3">baz (open)</option>
<option value="4">boo (open)</option>
</select>
...
</form>
...
</body>
...
HTH
PointedEars
--
The English government is much of a German poodle as
other governments. The Germans infiltrated them all.
-- "The only real Barbara Schwarz", dsw.scientology,
<16**************************@posting.google.com >)