I need to place two text fields and two buttons. The first one uses a dialog to select the file name and place it in the textbox.
The second selects the folder with which the user will work and places it in the second textbox.
Or another option: after clicking on the first button, the file name is placed in the first textbox, and its path without a name is placed in the second.
The problem is that no matter how I write the code, it always displays C:/fakepath/
I tried to at least just display the path using this code and also got a fake pass:
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<label for="fileInput">File Input:</label>
<input type="file" id="fileInput">
<input type="text" id="inputTxt"><br><br>
<button style="background-color: blue;" id="browseFile">Browse File</button><br><br>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$('#browseFile').click(function(){
$('#fileInput').click();
});
$('#fileInput').change(function(){
var filePath = $(this).val();
$('#inputTxt').val(filePath);
});
});
</script>
</body>
</html>
User220321 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.