-2

how to write a function in input type =file in php.Html code without echo statement is working well as copying the path to textbox.

  <form name="profile" method="post" enctype="multipart/form-data">
  <?php
      echo '<p style="margin-left:1cm"><input type="text" id="file2" size=18 maxlength=500><input type="file" name="bfile2" onchange="CopyMe(this, 'file2');" /></p>';
   ?>
 </form>

 <script>
function CopyMe(oFileInput, sTargetID) {
   document.getElementById(sTargetID).value = oFileInput.value;
}
Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
geetha
  • 3
  • 2

1 Answers1

1

Your problems lies in this section:

CopyMe(this, 'file2');

The ' character is breaking your echo. Escape the characters with \.

So your code ends up as:

echo '<p style="margin-left:1cm"><input type="text" id="file2" size=18 maxlength=500><input type="file" name="bfile2" onchange="CopyMe(this, \'file2\');" /></p>';
SharpC
  • 6,974
  • 4
  • 45
  • 40
Ole Haugset
  • 3,709
  • 3
  • 23
  • 44