Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Gmail feature

  1. #1
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Gmail feature

    On gmail if you click the 'attach file' link a text box and browse button appears. How can this be replicated?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
    function toggleVisibility(el) {
      if(el.style.display === "none")
        el.style.display = "";
      else el.style.display = "none";
    }
    </script>
    <p><button onclick="toggleVisibility(document.getElementById('attachDiv'));">Attach File</button></p>
    <p id="attachDiv">
      <form action="">
        <input type="file" name="userfile">
        <input type="submit" value="Go">
      </form>
    </p>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Location
    Dubai, UAE
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    JavaScript
    Code:
    function toggle(id) {
    	var obj = "";
    
    	// Check browser compatibility
    	if(document.getElementById)
    		obj = document.getElementById(id);
    	else if(document.all)
    		obj = document.all[id];
    	else if(document.layers)
    		obj = document.layers[id];
    	else
    		return 1;
    
    	if (!obj) {
    		return 1;
    	}
    	else if (obj.style)
    	{
    		obj.style.display = ( obj.style.display != "none" ) ? "none" : "";
    	}
    	else
    	{
    		obj.visibility = "show";
    	}
    }
    HTML
    Code:
    <a href="#" onClick="javascript:toggle('attach');">Attach another file</a>
    <div id="attach" style="display:none;"><input type="file" name="file_name"></div>
    Hopefully that can help you.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This one has more support for obsolete browsers. However, it can be condensed:
    Code:
    function toggle(el) {
    	var obj = document.getElementById && document.getElementById(el) ? document.getElementById(el) :
    		document.all && document.all[el] ? document.all[el] :
    			document.layers && document.layers[el] ? document.layers[el] :
    				el;
    	// if obj.style isn't defined, it hasn't been hidden
    	// in the first place, since we've used CSS to do so.
    	obj.style.display = obj.style.display === "none" ? "" : "none";
    }
    Code:
    <a href="#" onClick="javascript:toggle('attach');">Attach another file</a>
    <div id="attach" style="display:none;"><input type="file" name="file_name"></div>
    • The OP asked for a button;
    • that # will wreak havoc if you don't return false; from the event handler or, even better, use javascript:void(0); instead;
    • the javascript: pseudo-URL schema has no place in an event handler: javascript: is for URLs;
    • <input> elements must be in a form.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Location
    Dubai, UAE
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    • The OP asked for a button;
    • that # will wreak havoc if you don't return false; from the event handler or, even better, use javascript:void(0); instead;
    • the javascript: pseudo-URL schema has no place in an event handler: javascript: is for URLs;
    • <input> elements must be in a form.
    I am sure there is a 1 million ways to do it, I just posted up one that could be used.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It can't, really. That # will irritate users no end; it's still not what the OP actually asked for; and javascript: really shouldn't be parsed in event handlers (although it is error-corrected and ignored).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I think the best way would be appending nodes with javascript(dynamically).

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not really, since the OP only specified one box, so we can avoid using the slow DOM methods.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey, What is OP?? Option Provider or something??

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Original Poster -- the one who started the thread (and usually the one who asked the question).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •