0

I'm building a form where a description field changes it's content based on the input (onchange event) of the form. I have multiple input fields and each have their own description.

What I have been doing in the past is for each field (this is a very small examle):

var wisdom  = [' ', 'Seeker of Wisdom', 'Collector of Wisdom', 'Devotee of Wisdom', 'Devourer of Wisdom', 'Font of Wisdom', 'Oracle of Wisdom', 'Source of Wisdom'];
var wisdomp = [0, 100, 250, 550, 1200, 2500, 5000, 10000, 10000];

But initializing all these vars on the page doesn't seem right to me and creates a huge block of text. That's why I thought it would be better to read this data from an external file. I couldn't find a javascript file reader though.

Is there any better structure or method to keep and retrieve data using javascript?

2 Answers 2

1

in fact, you can use json to describe a k/v structure that seems to match your need:

{' ':0,'Seeker of Wisdom':100,'Collector of Wisdom':250 } and so on

note that you can also use nested structures as well using this notation.

see: http://www.json.org

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that should work in creating my variables more dynamic and reduce space. Is it actually OK to initialize all these vars on the relevant page?
0

jQuery create select list options from JSON, not happening as advertised? is more popular alternative to mentioned problem. would not bet on it being any better

2 Comments

I'm not sure what you're trying to say. Did you also propose to use JSON, or a variant of it?
yep, same json. given URL looks at it with more detail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.