Javascript Get Filename Of HTML Form Input File

When I wanted to get the filename of the file I just uploaded from the HTML form using Javascript, I found out that Internet Explorer and Firefox both output differently (yeah, this is the consequence for always sticking to Firefox). IE outputs the absolute path of the file (this means, it includes the root folder and its subdirectories) while Firefox outputs only the filename. I was expecting even Google Chrome to behave like Firefox but it turned out it gave the same result as IE. If you wish to know if Mac’s Safari browser does output the same as IE and Chrome, then the answer is yes (notice Safari and Chrome’s HTML form file input design is the same? This was done on purpose to avoid a common security flaw). To get around this problem, you would have to check the input file field if there are any \ or / characters in it, and if so, using the lastIndexOf() method to return the position of the occurence of the searched string, use it together with the substring() function. See the function below.

function getFilename(input_file_id) {
  file = document.getElementById(input_file_id).value;
  if (file.indexOf('/') > -1) file = file.substring(file.lastIndexOf('/') + 1);
  else if (file.indexOf('\\') > -1) file = file.substring(file.lastIndexOf('\\') + 1);
  return file;
}

The parameter I used for the function is the id name of the element since I prefer getting elements by id rather than using their form’s names.

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...

Connect To Your Mac Using Real VNC From Windows

I hope this would help mac os users who want to access their mac units remotely using Real VNC from a windows unit, be it desktop or laptop. The problem I had when enabling screen sharing in my MacBook was that after I try to connect using Real VNC, the program just closes. Not even an error message. That left me annoyed because I couldnt get it to work. Luckily after scouring the net, I came upon a forum wherein one user’s post made it work. Upon starting Real VNC, go to OPTIONS, then do the following

- Turn off Render Cursor Locally

- Set color to full color

That’s it.

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(4 votes, average: 5.00 out of 5)
 Loading ...

Google Chrome Revisited

Ok, so I’ve been using Chrome for quite sometime now and it’s time for me to jot down my negative feedbacks regarding this browser. Although I have grown fond of using this browser because of its simplicity, there are still other features that have disappointed me. Well, it is still BETA so I hope they will make changes with them soon. And … I hope it won’t be forever called BETA just so it will be used as an excuse for some of its deficiencies.

1) Obvious fact that there is no plugin support for now, it would have been nice to have the same plugin that Firefox has that disables all Flash embedded unless you click to enable and view them. This saves loading time which is a serious problem when using Chrome since the page can take longer to finish loading everything if there are Flash embedded in there, and sad to say sometimes the browser hangs up a bit (don’t tell me I have to have more RAM).

2) Download manager does not have a “REMOVE ALL” option to remove all files. I would have to remove them one by one, sheesh.

3) Cookies are already enabled but data that I placed in forms do not appear when I visit the same page. I mostly have to retype everything.

4) Javascript console sucks. Firefox’s Javascript console is better and easily clean and understandable for debugging. I don’t even know what to do with the Javascript console and Debug Javascript option.

5) I’m not sure if this is a popup security measure, but I’m annoyed that I can’t view one of the sites that I use for online transactions since it doesn’t let it pop open a new window.

6) Its search feature is lacking. It doesnt go over text that are inside a textarea for example, while Firefox does it seamlessly.

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...

Java Get Image Width And Height

The ImageIcon class under javax.swing package tends to be overlooked as it contains nifty methods to get an Image’s dimension. Just pass the path of the image file as parameter when you create a new ImageIcon instance then use either the getIconWidth() or getIconHeight() methods to get the width and height respectively.

ImageIcon ic = new ImageIcon(pathToFile);
System.out.println("width = " + ic.getIconWidth());
System.out.println("height = " + ic.getIconHeight());

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...