Forum Moderators: open

Message Too Old, No Replies

Using onchange to populate field on form

         

Novian

6:44 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



Hi there,

I'm totally new to this world having come from Flash. Please bear with me.

Okay, I'm using an aspSmartUpload.asp to upload an image to my server. On the same page, I have a empty field waiting for the name of the image I upload (imagefilename). I'm wondering how I automatically grab the imagefilename when I upload the file and dump it into my field. I'm thinking that onchange is the way to do it but it's not quite working. Here's my code:

<form action="/scripts/aspSmartUpload/Sample1.asp" method="post" enctype="multipart/form-data">
<input type="file" name="Filedata" size="40" onchange="document.mainform.imagefilename.value=getfilename(this.value)"><br>
<input type="submit" value="Upload">
</FORM>

RonPK

7:08 am on Jul 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello Novian,

Try this:

onchange="document.mainform.imagefilename.value = this.value"

Sometimes things turn out to be easier then expected ;)

Novian

1:33 pm on Jul 29, 2004 (gmt 0)

10+ Year Member



Hi RonPK,

Thanks for the reply. Unfortunately, it still doesn't want to work.

Here's an additional question: Does the fact that the form action calls in another page prevent the mainform from assuming any new values? I've noticed that onchange examples remain on the same page, call up a pop-up window or store the new values temporarily e.g. in a db

Here's the code again:

<form action="/scripts/aspSmartUpload/Sample1.asp" method="post" enctype="multipart/form-data">
<input type="file" name="Filedata" size="40" onchange="document.mainform.imagefilename.value=getfilename(this.value)"><br>
<input type="submit" value="Upload">
</FORM>

Thanks.

natty

2:14 pm on Jul 29, 2004 (gmt 0)

10+ Year Member



hi there,

if you are uploading an image then maybe you could do what we do , which is have an image holder and when the onchange of the file upload is fired, we set the src of the holder to the path of what is in the file upload bit. and then you can see which file it is that is attempting to be uploaded

onchange="document.all.imageholdername.src = fileupload.value;"

for ie only , but u get the idea i hope.

gl

nat

a small addition. might do as well to make sure the paceholder has a width and height or someone will try to upload a big pic and it will ruin how the upload form page looks..