check for consecutive integer values, ordered values

G

GIMME

If I have :

<input name="a1" value="1">
<input name="a2" value="3">
<input name="a3" value="2">

And I want the user to enter the values 1,2, and 3 but not
necessarily in that order .... (The user is "reordering" some
objects associated with the application, the actual reordering
occurs on the server side.)

Is there a clean way to have javascript
check that the entered values are 1,2, and 3?

Um ... Is the best and only approach to put all the a* values
in an array and looping to see if all values
have been entered? That works but somehow it
seems like there should something simpler.

Just looking for a tip on how to best proceed ....

Thanks.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in news:comp.lang.javascript said:
If I have :

<input name="a1" value="1">
<input name="a2" value="3">
<input name="a3" value="2">

And I want the user to enter the values 1,2, and 3 but not
necessarily in that order .... (The user is "reordering" some
objects associated with the application, the actual reordering
occurs on the server side.)

Is there a clean way to have javascript
check that the entered values are 1,2, and 3?

Um ... Is the best and only approach to put all the a* values
in an array and looping to see if all values
have been entered? That works but somehow it
seems like there should something simpler.

Just looking for a tip on how to best proceed ....

Put the values into an array, sort(), and check that the zeroth entry is
1, the oneth 2, the twoth 3, etc.

It might be better to redesign the dialogue to display all items in the
initial order and allow items to be moved. A simple, but not foolproof,
way would be to list all values in an input control and call for
drag'n'drop. Better would be to select one item to be moved, and where
it is to be moved to, and perform the move.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top