SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File Upload onClick

    I am providing an option for a user to either enter a url or upload a file but not both. To do this I am sending an error message and asking if they want the previous value that was set to "" When they answer yes and I try setting document.formName.fileUploadField.value = "" I get a security error, how do I set that text field next to the browse button to "".

    Also, how do I prevent the dialog that browses for files from opening if the URL field has data in it?

    Thank you,
    Brett

  2. #2
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I can't set a file to upload because that would just be bad security all together for my poor client, so cancel that question. Anyone have any thoughts on the stopping the dialog?

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    File upload fields are pretty well encapsulated: imagine the mischief that would be possible if they provided scriptable access to a user's drives. The only thing that comes to mind is calling Form.reset(); you might need to put the upload widget in its own form to keep things orderly.
    Code:
    <input name="url"><br />
    <input type="file" onclick="return (url.value=='')">
    ::: certified wild guess :::

  4. #4
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent, thank you. One more question though. Why is it that the text field of the file input doesn't take focus or blur? Yet, the browse button next to the text field takes focus and blur. Sort of frustrating.... Any suggestion of overcoming this barrier?

  5. #5
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interestingly this only happens in firefox and ns. Now, opera is even more screwed up, it seems to think a blur() is a focus. In my input type=file onblur="alert('file')" event occurs when I click on the file text field. Yuck.


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
  •