Creating a browse button.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas251074
    New Member
    • Dec 2007
    • 198

    Creating a browse button.

    How can I create browse button in ASP using JavaScript. Onclicking browse button, an explorer windows should open from which user should select file for attachment.

    Thanks and regards,
    Vikas
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by vikas251074
    How can I create browse button in ASP using JavaScript. Onclicking browse button, an explorer windows should open from which user should select file for attachment.

    Thanks and regards,
    Vikas
    Add an input dynamically and provide type=file to it. Or use this code.
    Code:
    document.getElementById('file_div').innerHTML = '<input type="file" name="myfile" />';
    where file_div is the id of the div where you want to add this.

    Comment

    • vikas251074
      New Member
      • Dec 2007
      • 198

      #3
      Originally posted by hsriat
      Add an input dynamically and provide type=file to it. Or use this code.
      Code:
      document.getElementById('file_div').innerHTML = '<input type="file" name="myfile" />';
      where file_div is the id of the div where you want to add this.

      Thanks very much

      Regards,
      Vikas

      Comment

      • vikas251074
        New Member
        • Dec 2007
        • 198

        #4
        Hello sir,
        Code:
        <script language="javascript">
        document.getElementById('file_div').innerHTML = '<input type="file" name="myfile" />';
        </script>
        What does this line do? Whether it creates browse button or anything else.
        When I add above in HTML part of programme, it does nothing. What is the reason sir.

        Thanks and regards,
        Vikas

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by vikas251074
          Hello sir,

          What does this line do? Whether it creates browse button or anything else.
          When I add above in HTML part of programme, it does nothing. What is the reason sir.

          Thanks and regards,
          Vikas
          Of course it adds a browse button (technically:fi le input) as you asked.

          But it has one requirement. You need to have a div in your page with id="file_div".

          So where you want this button to be added, add <div id="file_div"> </div> in your HTML.

          innerHTML dynamically adds HTML to an element of the document. Google for its purpose, you will understand it.

          And use type="text/javascript" instead of language="javas cript"

          Comment

          Working...