5 Replies - 1192 Views - Last Post: 01 October 2012 - 06:45 AM

#1 Joepiooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-February 10

$_GET echo language in Javascript file

Posted 01 October 2012 - 02:38 AM

Hello,

I have a website with diffrent languages.

That is working perfect but I got a problem with a form...

I have a form that reloads on change and then the URL is different:

In my index I use this code:

if(!isset($_GET['lang']))
    {
        include "talen/nl.php";
        $lang = "nl";
    }
    else
    {
        include "talen/".$_GET['lang'].".php";
        $lang = $_GET['lang'];
    }


I have a Javascript file that is working like this:

 "reloadForm" : function(form, merk, model)
    {
        var val = form.options[form.options.selectedIndex].value,
        data = "";
        if(merk != '')
        {
            data = data + "&merk=" + merk;
            if(model != '')
            {
                data = data + "&model=" + model;
                data = data + "&type=" + val;
            }
            else
            {
                data = data + "&model=" + val;
            }
        }
        else
        {
            data = data + "&merk=" + val;
        }
        window.location = "index.php?lang=nl&p=9&search=wiel" + data + "#keuze";
    }


Everywhere I can change language with onclick and href like this for example:

	

<a href="?lang=<?php echo $lang; ?></a>


No in my Javescript file above I manualy entered the language (lang=nl)

But I want to have this set dynamicly like the rest of my website...

How can I realise this because I'm stuck now

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: $_GET echo language in Javascript file

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,333
  • Joined: 08-June 10

Re: $_GET echo language in Javascript file

Posted 01 October 2012 - 02:44 AM

you can find the language in the URL to which you have access via window.location (or document.URL). you can extract the language from there.
Was This Post Helpful? 0
  • +
  • -

#3 Joepiooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-February 10

Re: $_GET echo language in Javascript file

Posted 01 October 2012 - 03:13 AM

Thanks for the fast reply.

I'm very sorry but I have no idea what you mean by what you just said...

Can you give an example?
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: $_GET echo language in Javascript file

Posted 01 October 2012 - 04:28 AM

The window.location.search property contains the GET key-value pairs in the URL. So if you have the URL: index.php?lang=nl&p=9&search=wiel, that property will contain:
?lang=nl&p=9&search=wiel.

All you have to do is have your code examine the property and extract the lang value, if it is there. I suggest using a Regular Expression. Or, if you're not comfortable with those yet, you could simply split the string into key-value pairs on the & char, and then each key-value pair into keys and values on the = char.


P.S.
I've moved this into the Javascript forum. This is not really a PHP related issue.

This post has been edited by Atli: 01 October 2012 - 04:30 AM

Was This Post Helpful? 0
  • +
  • -

#5 Joepiooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-February 10

Re: $_GET echo language in Javascript file

Posted 01 October 2012 - 05:12 AM

Ok so what you are saying it when I use window.location.search

It should remember my previous url?

something like this?

window.location.search = "index.php?p=9&search=wiel" + data + "#keuze";


but then with "lang=the-language"

Pfff how hard can it be...
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: $_GET echo language in Javascript file

Posted 01 October 2012 - 06:45 AM

View PostJoepiooo, on 01 October 2012 - 12:12 PM, said:

Ok so what you are saying it when I use window.location.search

It should remember my previous url?

No, not at all. It shows you the current URL. Or, at least, the query-string (GET values) part of it.

View PostJoepiooo, on 01 October 2012 - 12:12 PM, said:

something like this?

window.location.search = "index.php?p=9&search=wiel" + data + "#keuze";

No. That makes no sense. You are supposed to use window.location.search to find the language, so that you can use it with window.location to redirect with the correct language.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1