By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,567 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,567 IT Pros & Developers. It's quick & easy.

Creating a browse button.

vikas251074
100+
P: 198
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
Jun 2 '08 #1
Share this Question
Share on Google+
4 Replies


hsriat
Expert 100+
P: 1,654
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.
Expand|Select|Wrap|Line Numbers
  1. 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.
Jun 2 '08 #2

vikas251074
100+
P: 198
Add an input dynamically and provide type=file to it. Or use this code.
Expand|Select|Wrap|Line Numbers
  1. 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
Jun 2 '08 #3

vikas251074
100+
P: 198
Hello sir,
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. document.getElementById('file_div').innerHTML = '<input type="file" name="myfile" />';
  3. </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
Jun 3 '08 #4

hsriat
Expert 100+
P: 1,654
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:file 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="javascript"
Jun 3 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.