1

I have a set of PHP language files which I use to output text to the user based on the their language choice. I have passed the PHP variables to javascript successfully and they are available as LANG You can see it in use in the code.

Here is my question... Since the code as shown below works perfectly, why can I not change this line...

'No': { 'class' : ''}}

to

LANG.no: { 'class'  : ''}}

Basically I want to know why I can use LANG elsewhere in the code but not in the line shown above or in the equivalent "Yes" line.

Here is the working code:

$.confirm({
    'title': LANG.return_to_exhibit_lobby,
'message': "<strong>"+LANG.return_to_exhibit_lobby_confirmation+"</strong>",
'buttons': {
'Yes': { 
    'class': 'special',
    'action': function(){
        window.location.href='logout.php';
    }},
'No': { 'class' : ''}}
});
3
  • Why? Because the confirm code expects "No"? and it would need to look like Lang : { no : { class... } } Commented Apr 25, 2013 at 16:59
  • @epascarello I don't think that is true because I could change it to something absurd like 'banana'. I just can't but a variable name... Only a string. It can be anything... doesn't have to be "No" Commented Apr 25, 2013 at 17:01
  • @epascarello I tried the code as you suggested and it outputted "LANG" instead of "No" Commented Apr 25, 2013 at 17:05

2 Answers 2

4

What you could do instead:

var params = {
    'title': LANG.return_to_exhibit_lobby,
    'message': "<strong>"+LANG.return_to_exhibit_lobby_confirmation+"</strong>",
    'buttons': {
        'Yes': { 
            'class': 'special',
            'action': function(){
                window.location.href='logout.php';
             }}
};

params.buttons[LANG.No] = { 'class' : ''};

$.confirm(params);
Sign up to request clarification or add additional context in comments.

Comments

4

That's because you're in an object literal. Syntax rules are different there because you are declaring a structure, not acting on it. You could do this:

var data = {
    'title': LANG.return_to_exhibit_lobby,
    'message': "<strong>"+LANG.return_to_exhibit_lobby_confirmation+"</strong>",
    'buttons': {}
};
data.buttons[Lang.No] = { 'class' : ''}
$.confirm( data );

2 Comments

You need to declare buttons first. params.buttons = {} or do as I did in my edited answer
@SimonBoudrias I saw that just before you posted that I forgot to do it. I fixed it and it works now. Thanks!

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.