473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Image browse Button onclick

Hi
Is there a way to make the browse button an image?

I want a browser button with an attach image to browse files.
Please share the javascript code.
u can contact me in this email: [removed]
Apr 9 '13 #1
9 4184
Dormilich
8,658 Expert Mod 8TB
you can use the <button> element (which can contain images) and set it as file type button.
Apr 9 '13 #2
Hi Dormilich could you please share the code as i am new in the field of Javascripts.
Apr 9 '13 #3
Dormilich
8,658 Expert Mod 8TB
gonna be difficult, as the code is in HTML.
Apr 9 '13 #4
ya its ok but could you pls share that code with me..pls..
Apr 9 '13 #5
Dormilich
8,658 Expert Mod 8TB
there is nothing much to share, the definition of a button is here, and for an image here. you just need to combine it.
Apr 9 '13 #6
yes i have done that but not working:
Here is my HTML Code:
Expand|Select|Wrap|Line Numbers
  1. <button onclick="javascript:fileSelected();" >
  2.                                 <input type="image" src="logo-attachment.png" alt="" id="myimage"  />
  3.                                 <br />
  4.                             </button>
and here is my Javascripts code:
Expand|Select|Wrap|Line Numbers
  1. function fileSelected() {
  2.     alert('Testing');
  3.     // hide different warnings
  4.     document.getElementById('upload_response').style.display = 'none';
  5.     document.getElementById('error').style.display = 'none';
  6.     document.getElementById('error2').style.display = 'none';
  7.     document.getElementById('abort').style.display = 'none';
  8.     document.getElementById('warnsize').style.display = 'none';
  9.     alert(document.getElementById('myimage').files[0]);
  10.     // get selected file element
  11.     var oFile = document.getElementById('myimage').files[0];
  12.     //img.src = "logo-attachment.png";
  13.     //var oFile = document.getElementById('myimage').src = "logo-attachment.png";
  14.  
  15.  
  16.     // filter for image files
  17.     var rFilter = /^(image\/bmp|image\/gif|image\/jpeg|image\/png|image\/tiff)$/i;
  18.     if (! rFilter.test(oFile.type)) {
  19.         document.getElementById('error').style.display = 'block';
  20.         return;
  21.     }
  22.  
  23.     // little test for filesize
  24.     if (oFile.size > iMaxFilesize) {
  25.         document.getElementById('warnsize').style.display = 'block';
  26.         return;
  27.     }
  28.  
  29.     // get preview element
  30.     var oImage = document.getElementById('preview');
  31.  
  32.     // prepare HTML5 FileReader
  33.     var oReader = new FileReader();
  34.         oReader.onload = function(e){
  35.  
  36.         // e.target.result contains the DataURL which we will use as a source of the image
  37.         oImage.src = e.target.result;
  38.  
  39.         oImage.onload = function () { // binding onload event
  40.  
  41.             // we are going to display some custom image information here
  42.             sResultFileSize = bytesToSize(oFile.size);
  43.             document.getElementById('fileinfo').style.display = 'block';
  44.             document.getElementById('filename').innerHTML = 'Name: ' + oFile.name;
  45.             document.getElementById('filesize').innerHTML = 'Size: ' + sResultFileSize;
  46.             document.getElementById('filetype').innerHTML = 'Type: ' + oFile.type;
  47.             document.getElementById('filedim').innerHTML = 'Dimension: ' + oImage.naturalWidth + ' x ' + oImage.naturalHeight;
  48.         };
  49.     };
  50.  
  51.     // read selected file as DataURL
  52.     oReader.readAsDataURL(oFile);
  53. }
What's wrong here i don't know...
Please help me out..
Apr 9 '13 #7
Dormilich
8,658 Expert Mod 8TB
What's wrong here i don't know...
well, buttons have a default type, if you do not set one.

and images are not defined through an <input> element. besides that, what is a button inside a button supposed to be?
Apr 9 '13 #8
its a image of "Attach" and i want that image to be a browse button so that i can browse files and attach files in an email. By the way , could you please rectify my faults in the above mentioned codes and post it here.
Apr 9 '13 #9
Dormilich
8,658 Expert Mod 8TB
I’ve already told you what’s wrong with your HTML.
Apr 9 '13 #10

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

Similar topics

2
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
0
by: Jonathan | last post by:
Hi everyone, I have been trying to change my browse button appearance displayed with my HtmlInputFile control but without any success. The solution I tried was the one discuss on this forum...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
2
by: conckrish | last post by:
Hi all, This is all about ASP.NET WEB APPLICATION... I have a Button and when i click that button... i need to open the File Dialog through Which i have to select the Image Path... And When...
1
by: akshakeel | last post by:
Hi all, Is it possible to apply style to browse button, the code for which is, <input type="file"> I want to add a background image to the "Browse" button. (using css) But the problem im...
0
by: sreenulanka | last post by:
when i am clicking the browse button image not opened in my applet please help me. // browse button, generate browse event when it clicks if (e.getSource()==browse) { ...
8
by: gomzi | last post by:
Hi, I would like to know as to how one could replace the normal browse button (file upload control) with an image. Thanks, Gomzi.
9
by: shapper | last post by:
Hello, Is there a way to make the browse button an image? Thanks, Miguel
0
by: Bobby Edward | last post by:
All of a sudden my "Browse..." button doesn't work anymore. This is the button in the CSS "Modify Style" dialog for "background-image:". I've rebooted and it still fails. Any idea how to fix...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.