hi there... i'd like to know if it's possible to copy a selected file's name (value?) and insert it into a basic text field thru an onchange event handler...
here is my code: -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
-
<title>Untitled Document</title>
-
-
<script type="text/javascript">
-
-
function Copy()
-
{
-
document.getElementById('textfield').value = document.getElementById('filefield').value
-
}
-
</script>
-
-
</head>
-
-
<body>
-
<p>
-
<input type="file" name="filefield" id="filefield" onchange="Copy();">
-
</p>
-
<p>
-
<input type="text" name="textfield" id="textfield">
-
</p>
-
</body>
-
</html>
-
12 4040
i forgot to mention: this works fine, but what i'm trying to do is just copy the file's name, instead of copying the entire address of the file...
any ideas?
acoder 16,027
Recognized Expert Moderator MVP
Your code works absolutely fine in Firefox.
Your code works absolutely fine in Firefox.
hey acoder... yeah, i forgot to add what i was really trying to do... which is to copy the file's name only instead of the entire address of the file...
perhaps there's some insane code that could read the file, and copy only the text that's after the last "/" of the file's address? but i have zero ideas...
Yes, I missed your second post.
Use the string methods, in particular, lastIndexOf and substring.
thanks for the advice... but i'm finding it a little difficult wrapping my head around how i could use these to do what i'd like... would i use lastIndexOf with substring? or...
???
after searching/attempting for hours, this is the best i can come up with that makes any sense to me... but it doesn't work... :-/ -
function Copy()
-
{
-
document.getElementById('textfield').value = document.getElementById('filefield').value;
-
document.getElementById('textfield').value.substring(lastIndexOf('/') + 1);
-
}
-
acoder 16,027
Recognized Expert Moderator MVP
after searching/attempting for hours, this is the best i can come up with that makes any sense to me... but it doesn't work... :-/
You're almost there, just one correction: -
function Copy()
-
{
-
var fileVal = document.getElementById('filefield').value;
-
document.getElementById('textfield').value = fileVal.substring(fileVal.lastIndexOf('/') + 1);
-
}
-
You forgot the string object - lastIndexOf is a method of the String object.
You're almost there, just one correction: -
function Copy()
-
{
-
var fileVal = document.getElementById('filefield').value;
-
document.getElementById('textfield').value = fileVal.substring(fileVal.lastIndexOf('/') + 1);
-
}
-
You forgot the string object - lastIndexOf is a method of the String object.
oh sweet, yeah ok it's makes more sense now... thanks once again acoder!
i would like to note (for future references) that while implementing this discussions' code in my script, i came across an unexpected problem...
this code's onChange event handler will not fire if the file field attached to the onChange handler loads as a default style="display: none;" ... therefore it was necessary to choose a different placement for the onChange handler...
strange but true ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: tabonni |
last post by:
Hello All
I am creating an ASP page. There are a list of filename and checkbox
next to it. When user checked all the documents they want and click
ADD TO CLIPBOARD button. All filepaths will be copied into clipboard
and then they can right-click -> paste into MS Outlook as attachments.
How can I use clipboardData.setData function to do that? I saw a lot
of examples they are just copy and paste text.
|
by: Risto Heinonen |
last post by:
Hi.
I have a web page that has images and text. I can carefully select one
image and the on the right of the image and then copy & paste to Word.
Is it possible to make javascript do the same: select the same area
(divided by <div> tag) and copy to clipboard?
So far I succeeded to make the script to copy the area inside <div> but
it was plain html-text.
|
by: jerrygarciuh |
last post by:
Hi all,
The following script is giving me weird problems. I have in this
directory an index.php and hurricane.php.
If the script gets $i = 'on' it is supposed to back up the current
index into a file called normal.php and then copy hurricane.php into
index.php. This should create a backup of the index and then put the
hurrican alert in place.
|
by: Steve |
last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user
clicks on a toolbar button, the cut/copy/paste will work with whatever
textbox the cursor is current located in (I have about 20 textboxes on the
form). Also to ensure that the button can't get used if the cursor isn't in
a textbox field. And to ensure the contents of the clipboard are "text"
contents that have been cut/copied from one of the textboxes on the form.
...
|
by: =?Utf-8?B?R3JlZyBN?= |
last post by:
Hello,
I'm running an asp.net, intranet web application using .net framework 1.1 on
IIS5.1 / 6.0. Through the web application, I would like to press a button on
the web page, have another window (not web-based or part of current
application) brought to the front and focused (findwindow api) and have the
button scrape the contents of the focused window so the contents can be
parsed and entered into the web application.
Ideally, I would...
| |
by: Cliff72 |
last post by:
I need to fill in the nulls in the batch field the value from the
record immediately
preceding the null one ie replace the nulls with the preceding value
until I hit a record with a value in it--then hold the next value
through the next set of nulls, and so on.
See example below:
I wanna copy down batch "IMR138" in record ID 1, all the way to ID 10.
Then copy down batch "7138" all the way to ID 20 and so on....
|
by: Michael |
last post by:
I need to copy a huge file (around 300Mb) from a mapped network drive
to another.
I have created a console application and used System.IO.File.Copy
function.
But I want to know the process of this copying work.
Is there any way?
I am thinking that I can get the file size, but I don't know how to
get the size copied.
Thanks.
|
by: Jason |
last post by:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
|
by: raghudr |
last post by:
<?xml version="1.0" standalone="yes" ?>
- <AddressSpace xsi:noNamespaceSchemaLocation="prince.xsd" Name="U2"
ConfigMax="1" xmlns:xsi="http://www.rag.org/2001/XMLSchema-instance">
<Item Name="raj" VALUE="60864"/>
<Item Name="rag" VALUE="60868" />
</AddressSpace>
Hi all,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |