How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLPROG Your Own Question

ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7677
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now
A new question is answered every 9 seconds

I'm trying to access page variables that are in scope on an

Customer Question

I'm trying to access page variables that are in scope on an html, from within a Javascript on the same page.
Submitted: 2 months ago.
Category: Programming
Expert:  Steve replied 2 months ago.

Hi, my name is***** don't understand what the problem is?

Expert:  Steve replied 2 months ago.

But I think you're using the wrong syntax with some of your JQuery code

Expert:  Steve replied 2 months ago.

Can you give me a link to the HTML file or upload a file here with the code? That would be the easiest thing. Based on what you posted, I think maybe your ! should be || ?

Customer: replied 2 months ago.
Will do. Just a moment.
Expert:  Steve replied 2 months ago.

ok

Customer: replied 2 months ago.
Just to clarify. There are variables available atthe page level -- if you add the to the HTML they will print out. But when I try to use them in javascript I only get the variable names. Not the values.Here is the current code I am using.
Customer: replied 2 months ago.
The the is an error sending the file.
Customer: replied 2 months ago.
It will not post here either.
Can I email it to you?
Expert:  Steve replied 2 months ago.
Expert:  Steve replied 2 months ago.

And let me know when you've uploaded it.

Customer: replied 2 months ago.
Done.
Expert:  Steve replied 2 months ago.

OK, give me a few minutes to look at it.

Expert:  Steve replied 2 months ago.

What framework are you using?

Customer: replied 2 months ago.
I'm not sure.
Do you mean Jquery, etc.?
Expert:  Steve replied 2 months ago.

I know you're using jQuery. But <%= LastName %> is not standard JavaScript. Are you using a forms package or something else?

Customer: replied 2 months ago.
That was just my lastest effort to make it work.
Expert:  Steve replied 2 months ago.

Can you give me the whole HTML file?

Expert:  Steve replied 2 months ago.

It's hard to tell if all I can see is that snippet of code.

Customer: replied 2 months ago.
One sec. Those are Freemarker variables.
Customer: replied 2 months ago.
Unfortunately, no.
Expert:  Steve replied 2 months ago.

I don't know what to tell you then. If I can't look at the code, I can't help you. You have a typo in the firstname variable FYI.

Customer: replied 2 months ago.
Okay, Thanks for the effort.
Expert:  Bruce Wilner replied 2 months ago.

Hi. I would love to try to help you.

Let's make sure we know how we're proceeding.

Will you be able to provide the COMPLETE code that is not working and a precise description of how it was formerly working but now isn't, that is, what the difference is?

Also, I'm concerned that--when Steve asked you what some unrecognized syntax was--you answered that it was your "latest effort to make it work." I presume you're aware that you cannot just arbitrarily hack at code in undocumented ways, hoping that it will work. Programming languages do not work that way.

Would you be able to provide me that supplementary info? I will be looking forward to it. Thank you for your anticipated cooperation!

Customer: replied 2 months ago.
Bruce,Of course. Everything is done for a reason based on examples.This is not a case where there is "Working" in the sense you are thinking of. Here are the details:We have a page on a site where there are Freemaker variables in scope on that page. If you add the variable ${(contact.firstName)!(authContact.firstName)!} to the header blurb it will print in on the page.If I place it in side a Script, I can not assign it.Have you seen the code?
Expert:  Bruce Wilner replied 2 months ago.

I have not seen the code.

However, this is a case where things are or are not "working" in my narrow-minded sense. For, if the variables you endeavor to pass are out of scope, either of two things will happen: (a) it won't run at all; or (b) fresh instances of those variables will be instantiated, within the current scope, and they are guaranteed to have undesired values, either junk or whatever initializers are consonant with the language spec (e.g., zero integers, empty or even NULL strings, etc.).

You can assign to anything that can legally appear on the LHS of an '='. Do you mean that the assignments that you make are not reflected when you return to the calling module? That would make sense if the indicated variables were--as discussed--out of scope.

Kindly post the script (the relevant pieces, not thousands of lines' worth of extraneous code) with an indication of what variables are misbehaving; what attempts you are making to "pass" them (I put "pass" in quotes for the obvious reason); and what failed attempts you are making to modify them in the called function. You can use typographic conventions, like bold red font, to set things apart from their backgrounds--perhaps even preceded by bold red comments:

# this is where the variable is failing to properly be set

// some other language uses this comment convention, but same problem

$env{ foodle[ $doodle ] } = 4; <!-- I set it here in bar(), but it didn't take effect when i return to foo() -->