1

So, I tried everything that I know and I tried to find everywhere but no luck. I want to paste imdb link into (id="id_imdb") and then when I press button (name="b") I want that link to become variable $hjo and then to execute php script get_info_imdb.php and then return variable $slbl into javascript which will set textarea (name="movie_desc") to echo $slbl.

insert-movie.php

<html>
<body>
    <?php
    global $hjo;
    $hjo = "http://www.imdb.com/title/tt1431045/";
    include ("get_info_imdb.php");
    ?>
<form action="insert_movie.php" method="post" enctype="multipart/form-data">
        <div>
<div>
                <div>Description:</div>
                <div><textarea name="movie_desc" rows="7" cols="50" id="id_desc" value="<?php echo (isset($slbl))?$slbl:'';?>"></textarea></div>
            </div>
<div>
                <div>Imdb:</div>
                <div><input id="id_imdb" type="text" name="movie_imdb" size="50">
                    <button name="b" type="button">Button</button></div>
            </div>
<div>
                <div><input type="submit" name="submit" value="Publish"></div>
            </div>
</form>
<script type="text/javascript">
function myFunction() {
  document.getElementById("id_desc").value = "<?php echo $slbl; ?>";
}
</script>
</body>
</html>
<?php
...here is script to insert in database which is working...
?>

get_info_imdb.php

<?php
        include ("simple_html_dom.php");
        $html = new simple_html_dom();
        $html->load_file($hjo);
        $html = $html->find('.summary_text', 0);
        $nesto = strip_tags($html);
        $nesto = trim($nesto);
        $slbl = $nesto;
?>
  • PHP is a pre-processor, there is no direct two way communication between the source script and the resultant HTML that the browser gets ... – Jaromanda X Feb 14 '16 at 01:29
  • you can call `get_info_imdb.php` through javascript and then set the ` – fusion3k Feb 14 '16 at 01:33
  • @JaromandaX Yeah i found that, but i really dont know script in php that gives the same function. – Stefan Zupanek Feb 14 '16 at 01:34
  • @fusion3k How? I'm pretty awful at web programming... – Stefan Zupanek Feb 14 '16 at 01:35
  • Interaction with the web and server can be achieved through ajax (there are other ways but this will be easier) so for starter you should read about that. And try using jquery ajax, it would be easier. – Adrian Feb 14 '16 at 02:01

1 Answers1

0

This is an example to explain how to perform your request through javascript and jQuery. It's only an example, you have to implement it wih your own code:

File get_info_imdb.php:

<?php
    
    $movieID = $_GET['id'];
    
    // Your code to retrieve movie info and chunk of HTML you want put in textarea
    
    echo $TextAreaValue;
    
?>

Fle insert-movie.php:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>

    <script type="text/JavaScript">
        function getHTML()
        {
            $.get( "get_info_imdb.php?id=tt1431045", function( data ) {
              $( "#myTextArea" ).html( data );
            });
        }
    </script>

    <form action="YourAction.php" method="YourMethod">
        <textarea id="myTextArea"></textarea>
        <button id="myButton" onclick="getHTML(); return false;">Click Me</button>
    </form>

</body>
</html>

In the <head><script> I load jQuery; In javascript function getHTML() I use jQuery get method to retrieve desired url (I have insert movie id, you can insert variable id with php) and put it into the content of textarea #myTextArea.

In the <form> the <button id="myButton"> call getHTML() js function.


fusion3k
  • 11,568
  • 4
  • 25
  • 47