0

I have this script tag , which takes the input from the user and passes it to the php block which is inside the same script tag and passes it to a URL and then fetches all the values , once all the values are fetched it then again uses javascript to print those values on the browser part without reload . So far I'am able to get the values from the URL and print it without reload , but that is when i initalize the value on the PHP url itself , all i want is to pass the javascript variable inside the php URL, so that whenever i write the keyword on the input box, it fetches the result.

Below is my script so far .

 <script language="JavaScript">
    function showInput() {


      var aaa=document.getElementById('display').innerHTML = document.getElementById("user_input").value;
      ///alert(aaa);
         <?php 
                             $abc ='0545010225';


           $xml = simplexml_load_file("http://lx2.loc.gov:210/lcdb?operation=searchRetrieve&recordSchema=marcxml&version=1.1&maximumRecords=10&query=bath.isbn%3D".$abc);
              $xml->registerXPathNamespace("slim", "http://www.loc.gov/MARC21/slim");
          $title = '/zs:searchRetrieveResponse/zs:records/zs:record[1]/zs:recordData/slim:record[1]/slim:datafield[@tag="245"]/slim:subfield[@code="a"]';
                $result_title = $xml->xpath($title)[0];
                $author = '/zs:searchRetrieveResponse/zs:records/zs:record[1]/zs:recordData/slim:record[1]/slim:datafield[@tag="100"]/slim:subfield[@code="a"]';
                $result_author = $xml->xpath($author)[0];
                $isbn = '/zs:searchRetrieveResponse/zs:records/zs:record[1]/zs:recordData/slim:record[1]/slim:datafield[@tag="020"]/slim:subfield[@code="a"]';
                $result_isbn = $xml->xpath($isbn)[0];
         ?>
         var t="<?php echo $result_title;?>";
         var a="<?php echo $result_author;?>";
         var i="<?php echo $result_isbn;?>";


         
            
    }


  </script>

All i am trying to do is pass the value of aaa inside abc

Harjeev Singh
  • 13
  • 1
  • 7
  • Just tell me one thing , what i am trying to do ,is it possible? . – Harjeev Singh Oct 15 '17 at 21:25
  • yes, but not this way. When the page is sent to the browser, the PHP is **done**, since it's server side only. Whatever you do now on the page - PHP doesn't know it. Unless you will use AJAX, or post a form, or use a redirection. See the link suggested: https://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php – konrados Oct 15 '17 at 21:48
  • alright . i'll check out this link . thanks – Harjeev Singh Oct 15 '17 at 21:50

0 Answers0