php code in javascript

  • fahim45
    Likes 0

    Problem Description

    how can i pass a value from url using javascript code? in the following code, i bold the part which i want to use. is it possible?

    suppose, http://www.sonarlearning.co.uk/questions.php?question-topic=598 ( the bold part ?question-topic=598)

    i use the following code:

    <script type="text/javascript">
                $(document).ready(function(){
                    
                    $("#btn-view").hide();
                    
                    $("#btn-add").click(function(){
                        $(".content-loader").fadeOut('slow', function()
                        {
                            $(".content-loader").fadeIn('slow');
                            $(".content-loader").load('video_add.php?lang=<?php echo $row[‘lang’];?>');
                            $("#btn-add").hide();
                            $("#btn-view").show();
                        });
                    });
                    
                    $("#btn-view").click(function(){
                        
                        $("body").fadeOut('slow', function()
                        {
                            $("body").load('video.php?lang=<?php echo $row[‘lang’];?>');
                            $("body").fadeIn('slow');
                            window.location.href="video.php?lang=<?php echo $row[‘lang’];?>";
                        });
                    });
                    
                });
            </script>


  • Sonar Systems admin
    Likes 0

    Yes it is, as long as the JavaScript code is in a PHP file. What your are doing should work fine.

  • fahim45
    Likes 0

    i am making my final year project. i don’t know everything. i am a beginner in web development. i this project i am trying use two languages.in php, i change my language like this http://www.sonarlearning.co.uk/questions.php?lang=<?php row $lang;?>. but some url is in javascript code. i can’t use <?php row $lang;?> in javascript code. but i want to pass $lang value in that code. how is it possible? please cooperate me.

  • Sonar Systems admin
    Likes 0

    You need to echo it out.

  • fahim45
    Likes 0

    i don’t understand clearly. please, describe me.

  • Sonar Systems admin
    Likes 0

    This should work like you showed

     

                            $(".content-loader").load('video_add.php?lang=<?php echo $row[‘lang’];?>');
     

Login to reply