Forum Moderators: open

Message Too Old, No Replies

dynamically change text input from file field

         

twistedperv

2:46 am on Apr 26, 2005 (gmt 0)

10+ Year Member



Ive found alot of help for people here with making a drop down menu change the value of a text field and Ive tried hacking it abit and making it work for me but to no avail.

What Im trying to do, is create 6 file fields for images. When the user selects an image with file field named gal_img_1, I need the text field img1 to show the name of the image itself, minus the directory path it came from.

This is in conjunction with a thumbnailer and image uploader I've already got working and is to input the image names into mysql along with all the other newly created information from the form.

Any help would be appreciated, Im at a road block

BlobFisk

10:42 am on Apr 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This looks like a job for split(). This will create an array from the string you are splitting with each array item being the portions of the string between your split control.

For example:


var thePath="path/to/my/image.gif";
var pathArray=thePath.split("/");

You image (sans path) will the be the last item in the array pathArray.

HTH

twistedperv

9:12 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



awesome bud! that'll work great from getting just the file name! the question now is how do I pass that file name down to the text field and have it dynamically change the value="" of that text field?

BlobFisk

10:55 am on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can set the value of and element by accessing it via the DOM and setting the value attribute:

document.getElementById('myTextField').value = 'Some New Value';

HTH