0

I need to access a javascript function which is in the separate file.

Here is what I am trying to do:

in the php file I have:

var session_lang= <?php echo $_SESSION['SESS_LANGUAGE'];?>;
    if (session_lang!='')
    {
        check_and_change(session_lang);
    }
});

and I have this check_and_change() function in that separate javascript file which is of course included.

One more thing. I am getting error that there is a unknown < sign, so probably my php variable can't be read. If someone can please check that too.

4
  • Take a look at console. What it say? Commented Jul 21, 2012 at 7:16
  • Check if there any php open tag not closed... Commented Jul 21, 2012 at 7:18
  • I am getting unexpected token at < sign Commented Jul 21, 2012 at 7:20
  • Where is the }); coming from? And what is getting parsed into the HTML output? Maybe an error is getting placed on the variable location causing the unknown < error. Commented Jul 21, 2012 at 7:26

1 Answer 1

1

If the error line is the line with the session_lang variable, then you forgot the double qoutes (if the session_lang is a string).

var session_lang = "<?php echo $_SESSION['SESS_LANGUAGE'];?>";
    if (session_lang!='')
    {
        check_and_change(session_lang);
    }
Sign up to request clarification or add additional context in comments.

6 Comments

Have you considered that $_SESSION['SESS_LANGUAGE'] might already contain those double quotes?
No I didn't, would be ugly though to add double qoutes to an variable that is probably used in other (none HTML) functions as well.
I'm aware of that, just saying, don't say it as if it were 100% correct, it's also possible that he doesn't have PHP enabled at all the the PHP tags are rendered on the page.
It is not working, now I am getting unexpected syntax ILLEGAL
got it to work. I forgot to put session_start(), new problem is that I can access that function which is in the included file
|

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.