View Single Post
Old 01-11-2013, 11:39 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Lookup table is easiest. External file may be best. You have to decide that part.

Lookup table is trivial:
Code:
var phrases = [
     null, /* 0 is never used */
     "this is phrase 1",
     "this is phrase 2",
     ..
     "this is phrase 140"
];
var chosenPhrase = phrases[document.getElementById('datamem14').value];
if ( chosenPhrase == null ) chosenPhrase = "That is not a valid selection";
As an alternative, if you wanted the value from datamem14 to be something other than a number form 1 to 140:
Code:
var phrases = {
    "auto" : "This is automatic",
    "manual" : "5 speed on the floor",
    "chain" : "Must be a bicycle",
    ...
}
var chosenPhrase = phrases[document.getElementById('datamem14').value];
if ( chosenPhrase == null ) chosenPhrase = "That is not a valid selection";
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
JS Newbie (01-11-2013)