0

I am having trouble in this functions. I would like to retrieve all the information and put the value into the input box straight away.

I tried using JavaScript and PHP code but I don't know why my code is not working.

HTML:

 <label>Em Part No</label>
 <input type="text" class="form-control" id="emPartNo_insert" placeholder="Em Part No" name = "emPartNo_insert" onkeyup="updating()" required="" autofocus="">
 <label>Description</label></br>
 <textarea class="form-control" id="description_insert" name="description_insert" form="moduleform_insert" placeholder="Description" required=""></textarea>

JAVASCRIPT WITH PHP Code

        function updating(){
        var emPartNo = document.getElementById("emPartNo_insert").value;
        <?php
        $partno_passing="<script>document.writeln(emPartNo);</script>";
        $sql = "SELECT * FROM partMaintainanceModule where emPartNo='$partno_passing'";
        $result = $connection->query($sql);
        if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {   
        ?>
        document.getElementById('description_insert').value =<?php echo $row["description"];?>;
        <?php
        }
        }?>

        }
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
dd dd
  • 1
  • 1
  • Mixing javascript and php like this is bad practice – Rotimi Nov 18 '17 at 06:50
  • 1
    1. The PHP is rendered in the client, so the contents of the function will be rendered when it hits the browser, not when executed by a call to the JS function. 2. You need to wrap strings in quotes and there cannot be any line breaks unless the quotes are backticks. 3. The `` will kill any script on the page so can only be used in external javascripts 4. Are you really looking up `where emPartNo = ''` ??? I have a strong feeling you indulge in wishful thinking here and need to investigate how PHP interacts with JS – mplungjan Nov 18 '17 at 06:50
  • assign id in input box and check .emPartNo_insert – Lomesh Kelwadkar Nov 18 '17 at 06:55
  • i tried to assign dy but nothing happens – dd dd Nov 18 '17 at 06:58
  • – Lomesh Kelwadkar Nov 18 '17 at 07:00
  • input type="text" class="form-control" placeholder="Em Part No" name = "emPartNo_insert" onkeyup="updating()" required="" autofocus="" id="emPartNo_insert"> – Lomesh Kelwadkar Nov 18 '17 at 07:01
  • Check u r out put in console. i think help this code – Lomesh Kelwadkar Nov 18 '17 at 07:01
  • Yar the console list out 444 when I input – dd dd Nov 18 '17 at 07:07

0 Answers0