| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Browse Button in HTML For Directory Selection Alone…Not File Selection
Topic: Browse Button in HTML For Directory Selection Alone…Not File Selection
I have an issue regarding wanting to put a Browse button on an html page that will allow a user to select a directory path....not a file.....on their local machine. That selected directory path then would get populated into a text input field submission on a web form. The scenario involves asking a person during a web based registration process where the user would like files downloaded locally to their machine. FYI the site is being built in ASP.NET. You want them to be able to hit a browse button, maneuver through a directory path on their local machine, select an end directory, and then have that directory path alone (meaning not being required to include a file name from within the directory) be populated into the input field for submission to the user's profile store. Does anyone have any samples of HTML code that shows how this is accomplished? Any good web site examples that can demonstrate this as well? Thanks in advance. Very much appreciated. Steve |
|
#2
|
||||
|
||||
|
just check the filed value with JavaScript, and make sure the last character is a "\"
|
|
#3
|
||||
|
||||
|
You will never receive a directory name back from the type="file" input button, but you could extract the directory from the filename:
Code:
<html>
<head>
<title>Return file directory</title>
<script language="JavaScript">
function GetDirectory() {
strFile = document.MyForm.MyFile.value;
intPos = strFile.lastIndexOf("\\");
strDirectory = strFile.substring(0, intPos);
alert(strFile + '\n\n' + strDirectory);
return false;
}
</script>
</head>
<body>
<form name="MyForm">
<input type="file" name="MyFile">
<input type="button" value="Get directory" onClick="GetDirectory();">
</form>
</body>
</html>
__________________
selwonk If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more! |
|
#4
|
|||
|
|||
|
is there no other way to do this?
any help appreciated. |
![]() |
| Viewing: ASP Free Forums > Web Design > Web Layout > Browse Button in HTML For Directory Selection Alone…Not File Selection |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|