vsoni
vsoni

Reputation: 497

how to get access set of values from html source to javascript for processing

I have set of values in html source coming from my template.

It looks like

var formValues = {value1 :'Y',  value2:'Y', value3:'N'}

How do i access them in my js file for processing.

Within the same source I have another variable

var myVar = 'myValue'

And I am able to access this var by just calling it in my javascript by myVar.

I have tried like formValues.value1 but it's not working.

Upvotes: 1

Views: 35

Answers (2)

msanford
msanford

Reputation: 12227

Where is your formValues declared with respect to where you attempt to read it?

JavaScript has function scope. I suspect that if you cannot access it, it's likely either within another function or is declared after you are looking for it.

Upvotes: 0

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

I'm not sure if that will solve the problem, but you have an extra s in formValues.values1 like @Hunan mentioned in comment, should be formValues.value1.

var formValues = {value1 :'Y',  value2:'Y', value3:'N'}
console.log(formValues.value1); //return Y

Hope this helps.

Upvotes: 1

Related Questions