473,396 Members | 1,804 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,396 software developers and data experts.

Validationg against a selection

HI all,
I'm new to html and havascript. 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.
Any help appreciated

Thanks
Robert
May 30 '06 #1
1 986
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 >)
May 30 '06 #2

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

Similar topics

15
by: lawrence | last post by:
Is this the correct way to test for a method before I use it? createRange() is, I believe, an IE only method. function wrapSelectionInTag(selection, tag) { if (document.selection.createRange)...
5
by: STeve | last post by:
Hey guys, I currently have a 100 page word document filled with various "articles". These articles are delimited by the Style of the text (IE. Heading 1 for the various titles) These articles...
1
by: colincolehour | last post by:
I have tried searching for tips or tutorials on validating an XML file against and XSD file in python but I haven't had any luck. Can someone point me in the right direction to how this would be...
12
by: Odalrick | last post by:
I need to draw visible lines on pictures with wxPython. That means I can't simply use, for instance, a black line since it wont be visible on a black or dark picture. Painting applications like...
3
by: redhat | last post by:
I'm stuck trying to compare date values from users selection against a database which is Access. This is my problem I get two date from client with mm/dd/yyyy format transfer via form to my asp...
0
by: Peter Anthony | last post by:
Granted, it doesn't fit the name 'replace in files' perfectly. But it is awkward sometimes when I open up 'replace in files' and realize I have to open up 'quick replace' if I want to replace just...
13
by: Bruza | last post by:
I need to implement a "random selection" algorithm which takes a list of as input. Each of the (obj, prob) represents how likely an object, "obj", should be selected based on its probability of...
10
by: thayes5150 | last post by:
I have an access database that uses a subform to display records, one column of which is charge data (currency). My users need to verify the charges against the paper form they are scanned from, so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.