SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    add value to <input type="file">

    My form has 3 images to be uploaded...more often then not the 3 images are named something like this image_S image_M image_L

    so i was writing a function to auto fill the _M and _L once i selected the _S image.

    here is my function

    Code:
    function auto_images() {
    	input_box=confirm("Auto-fill _MD and _LG images??");
    	if (input_box==true){ 
    		// Output when OK is clicked
    		var SM = document.forms.form1.product_image_sm.value;
    		if(SM.indexOf('_S.')){
    			var MD_a = SM.split('_S.');
    			var MD = MD_a.join('_M.');
    			var LG_a = SM.split('_S.');
    			var LG = LG_a.join('_L.');
    			alert(MD);
    			document.forms.form1.product_image_md.value = MD;
    			document.forms.form1.product_image_lg.value = LG;
    		}
    	}else{
    		// Output when Cancel is clicked
    	}
    }
    everything works except the part where I try to fill in the inputs value

    document.forms.form1.product_image_md.value = MD;
    does not work....can someone please advice the right way to do that?

    THANKS
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In javascript, inputs of type=file are read only.

  3. #3
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo View Post
    In javascript, inputs of type=file are read only.
    thats stupid...i think what I am trying to do is a completely legitament reason why it shouldn't be read-only...

    ok so in that case is there a way I can use javascript to erase the input field and then write a completely new input field with the value?

    or just overite the entire input field?



    I would really like to figure out a way to make these images auto-fill.....I am often adding around 100 products at a time. and hunting for 100 images in a folder filled with several images would be significantly more time efficient then hunting for 300.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  4. #4
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I changed my function to overight the input field with a new one with the value="" set but apperently the value="" atribute does not work on input files either.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  5. #5
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i guess my best solution is to innerhtml the string i want to insert into the input file right next to it and then just copy and paste it in.

    thanks.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  6. #6
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a security measure. If file-inputs were writable I would be able to do something like this:
    Code javascript:
    var input = document.createElement('input');
    input.type="file";
    input.value="Path/To/Your/Passwords";
    myForm.appendChild(input);
    myForm.submit();

    Your best option is probably just uploading the images as-is and saving them on the server-side with a different name.

  7. #7
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks IZE i guess thats why I can't find a hack to get it to work lol.

    writting it next to it and copy and pasting is close enough i guess lol.

    maybe what you said about server side is better anyways....they always the same picture just different sizes....i wonder if I can change the size as well as the name via php?....off to the php forums to find out..

    thanks.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  8. #8
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's certainly possible using PHP's GD Library
    But you're right, that's best discussed over there


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •