geetha geetha - 14 days ago 5
CSS Question

function in input type=file in php

how to write a function in

input type =file
in php.Html code without
echo statemen
t 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;
}

Answer

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>';
Comments