Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Location
    Australia
    Posts
    307
    Tokens
    0

    Default Javascript innerHTML

    I need some help with a script I'm using.

    I have a working script at the moment where I have a file field and you click the link and it adds more file options.

    But if I have already selected a file in the field and click Add More it removes the currently selected file.

    Here is the code:

    Code:
    <div id="addmoreimages">
    <input name="ufile[]" type="file" id="ufile[]" size="50" /><br>
    </div>
    
    <script type="text/javascript">
    function add_more_images(){
    document.getElementById('addmoreimages').innerHTML = document.getElementById('addmoreimages').innerHTML + '<input name="ufile[]" type="file" id="ufile[]" size="50" /><br>';
    }
    </script>
    
    <a href="javascript:add_more_images()">Add more images</a>
    +REP for any help.

    Thanks,
    Chris.

  2. #2
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    First result on google for "append innerhtml"

    HTML Code:
    <div id="addmoreimages">
    <input name="ufile[]" type="file" id="ufile[]" size="50" /><br>
    </div>
    
    <script type="text/javascript">
    function add_more_images(){
    	var mydiv = document.getElementById('addmoreimages');
    	var div = document.createElement("div");
    	div.innerHTML = '<input name="ufile[]" type="file" id="ufile[]" size="50" /><br>';
    	
    	while (div.firstChild) {
    	    mydiv.appendChild(div.firstChild);
    	}
    }
    </script>
    
    <a href="javascript:add_more_images()">Add more images</a>


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  3. #3
    Join Date
    Apr 2006
    Location
    Australia
    Posts
    307
    Tokens
    0

    Default

    Quote Originally Posted by Jewish Bear View Post
    First result on google for "append innerhtml"

    HTML Code:
    <div id="addmoreimages">
    <input name="ufile[]" type="file" id="ufile[]" size="50" /><br>
    </div>
    
    <script type="text/javascript">
    function add_more_images(){
        var mydiv = document.getElementById('addmoreimages');
        var div = document.createElement("div");
        div.innerHTML = '<input name="ufile[]" type="file" id="ufile[]" size="50" /><br>';
        
        while (div.firstChild) {
            mydiv.appendChild(div.firstChild);
        }
    }
    </script>
    
    <a href="javascript:add_more_images()">Add more images</a>
    Cheers.

  4. #4
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Just to let you know the reason why it was doing that.

    You was "selecting" a file, and having it already selected, then adding a new field.

    So what happened was it took that old field, completely erased it, and added it to the HTML with the new field.

Posting Permissions

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