Php variable gebruiken in java script

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Jordy R

Jordy R

24/12/2014 06:50:44
Quote Anchor link
ik wil graag een php variable gebruiken in javascript.
zit al even te google maar kom er niet uit.
en dit werkt ook niet iemand een oplossing.
Alvast bedankt

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<script>
     var open =<?"'.$openadvertenties.'";?>
    var bezet =<?"'.$GAdvertenties.'";?>
        var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
        var lineChartData = {
            labels : ["Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"],
            datasets : [
                {
                    label: "My First dataset",
                    fillColor : "rgba(220,220,220,0.2)",
                    strokeColor : "rgba(220,220,220,1)",
                    pointColor : "rgba(220,220,220,1)",
                    pointStrokeColor : "#fff",
                    pointHighlightFill : "#fff",
                    pointHighlightStroke : "rgba(220,220,220,1)",
                    data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
                },
                {
                    label: "My Second dataset",
                    fillColor : "rgba(151,187,205,0.2)",
                    strokeColor : "rgba(151,187,205,1)",
                    pointColor : "rgba(151,187,205,1)",
                    pointStrokeColor : "#fff",
                    pointHighlightFill : "#fff",
                    pointHighlightStroke : "rgba(151,187,205,1)",
                    data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
                }
            ]

        }
        
        var pieData = [
                {
                    value: var open;,
                    color:"#009ee3",
                    highlight: "#009ee3",
                    label: "open"
                                },
                {
                    value: var bezet;,
                    color: "#4D5360",
                    highlight: "#616774",
                    label: "bezet"
                }

            ];


    window.onload = function(){
        var ctx = document.getElementById("canvas").getContext("2d");
        window.myLine = new Chart(ctx).Line(lineChartData, {
            responsive: true
            
        });
        var ctx = document.getElementById("chart-area").getContext("2d");
                window.myPie = new Chart(ctx).Pie(pieData);

    }

    </script>

- Aar -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Gewijzigd op 24/12/2014 15:30:57 door - Ariën -
 
PHP hulp

PHP hulp

28/03/2024 19:10:43
 
- Ariën  -
Beheerder

- Ariën -

24/12/2014 08:34:19
Quote Anchor link
Gelieve je code tussen codetags te zetten.

Je moet je variable echo-en. ;-)
 
Frank Nietbelangrijk

Frank Nietbelangrijk

24/12/2014 09:23:12
Quote Anchor link
Klein voorbeeldje:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

$gebruiker
= 'Jan de behanger';

?>

<!DOCTYPE html>
<html>
    <head>
        <title>javascript</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div id="content"></div>
    </body>
    <script>
        window.onload = function() {
            var el = document.getElementById("content");
            el.innerHTML = "<?php echo $gebruiker; ?>";
        };
    </script>
</html>
 
Jordy R

Jordy R

24/12/2014 15:08:58
Quote Anchor link
dank jullie wel dat is het.
hoe makkelijk kan het zijn. dom van me

Thx
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.