Topic
  • 2 replies
  • Latest Post - ‏2012-10-01T13:24:16Z by Xeb
Xeb
Xeb
5 Posts

Pinned topic Locale setup using javascript

‏2012-09-28T15:10:45Z |
When I used anchor tag language switch works great, because I can hardcoded the value

<portal-navigation:url command="ChangeLanguage"><portal-navigation:urlParam name="locale" value="es"/></portal-navigation:url>

but I am using dropdown and trying to set value what used has selected but this time not working. code is below

function changeLang(selectedValue){
var varForm = document.getElementById("formLanguage");
alert(selectedValue); // this gives me es
// even if i set selectedValue manually to es like selectedValue='es'; does not work
varForm.action = <portal-navigation:url command="ChangeLanguage"><portal-navigation:urlParam name="locale" value="'+selectedValue+'"/></portal-navigation:url>;
varForm.submit();
}

seems like its just taking selectedValue as it is as a value not its value, Please Help me out. Is there any other way to achieve this??????
Updated on 2012-10-01T13:24:16Z at 2012-10-01T13:24:16Z by Xeb
  • SystemAdmin
    SystemAdmin
    30895 Posts

    Re: Locale setup using javascript

    ‏2012-09-28T20:45:43Z  
    I think your problem is a result of the fact that the <portal-navigation:url> tags are being evaluated by Portal long before your Javascript ever executes. Since the <portal-navigation:url> tags are not formed correctly at the time they are evaluated, you're probably getting garbage back.

    How many languages are you talking about here? A couple? A hundred?

    If it's only a couple, maybe you could do something like this:
    
    var actionES = 
    '<portal-navigation:url command="ChangeLanguage"><portal-navigation:urlParam name="locale" value="es"/></portal-navigation:url>'; var actionFR = 
    '<portal-navigation:url command="ChangeLanguage"><portal-navigation:urlParam name="locale" value="fr"/></portal-navigation:url>';
    

    Then your Javascript logic can just pick the appropriate value based on the user's selection and assign that to the action attribute of your form.
  • Xeb
    Xeb
    5 Posts

    Re: Locale setup using javascript

    ‏2012-10-01T13:24:16Z  
    I think your problem is a result of the fact that the <portal-navigation:url> tags are being evaluated by Portal long before your Javascript ever executes. Since the <portal-navigation:url> tags are not formed correctly at the time they are evaluated, you're probably getting garbage back.

    How many languages are you talking about here? A couple? A hundred?

    If it's only a couple, maybe you could do something like this:
    <pre class="jive-pre"> var actionES = '<portal-navigation:url command="ChangeLanguage"><portal-navigation:urlParam name="locale" value="es"/></portal-navigation:url>'; var actionFR = '<portal-navigation:url command="ChangeLanguage"><portal-navigation:urlParam name="locale" value="fr"/></portal-navigation:url>'; </pre>
    Then your Javascript logic can just pick the appropriate value based on the user's selection and assign that to the action attribute of your form.
    Thanks for the reply, Well Yes I realize that and right now I am using the same, but my concern is there any way I could change it to dynamic behavior?