SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    appendChild script not working

    I have this script that appends file input fields to a form when the user clicks on a button:

    Code:
    function addMultiFile(){
    
      	var slash = "\\"
      	var filePath = document.getElementById('firstFile').value;
      	var lastSlash = filePath.lastIndexOf(slash);
      	var path = filePath.substring(0, lastSlash+1);
      	
      	var form = document.getElementById('myForm');
      	var i;
      	for (i=0; i < 5; i++){
      		fileArray[i] = document.createElement('INPUT'); 
      		fileArray[i].type='FILE';
      		fileArray[i].id = 'userFile'+i; 
      		fileArray[i].name= 'userFile'+i;
      		fileArray[i].value = 'path'+i;
      		form.appendChild(fileArray[i]);
      		//alert ('fileArray['+i+'] = '+fileArray[i].id);
      	}
      }
    and its called like this :

    Code:
    <input type="button" value="Add Multi Files" onClick="addMultiFile()" id="multiButton" />
    strangely enough, it works fine in pc IE *AND* mac Safari...but not mac IE or netscape (any). Is there a better way to make this more cross-broswer compatible?
    From here on, it's instinctual...even straight roads meander.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    fileArray[i].setAttribute("type", "file");
    etc.
    etc.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks like that'll do it..thanks!!
    From here on, it's instinctual...even straight roads meander.

  4. #4
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...almost. doenst work for mac IE. not that big of a deal but if someone knows how to get it to work that would be good too.
    From here on, it's instinctual...even straight roads meander.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ppk's thoughts:
    Attributes
    A bloody mess. Try influencing attributes in this order:

    1. Try getting or setting a specific property, like x.id or y.onclick.
    2. If there is no specific property, use getAttribute() or setAttribute().
    3. If even that doesn't work, try any other method or property in the table below. Most have horrible browser incompatibility patterns, though.
    4. Avoid attributes[]. It's worse than anything else.

    http://www.quirksmode.org/dom/w3c_core.html

  6. #6
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, that link is awesome! thanks!
    From here on, it's instinctual...even straight roads meander.

  7. #7
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the attribution of path / file work for an input type file ?
    I thought it was impossible for security reasons ?

  8. #8
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    argh..thats what i was just coming back here to check out, i couldnt set the value of the file input fields. so close...
    From here on, it's instinctual...even straight roads meander.


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
  •