Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    JavaScript


Evaluate Last 4 Characters Of File Name Using Javascript

I have built a page on a recruitment website which allows users to upload their CV via ASPUpload i.e a browse button. However I want to limit the file type to just MS Word documents as I do want them uploading large PowerPoint files etc. My idea is to have some javascript which evaluates the last 4 characters of the file name to ensure it is .doc
So if they try to upload anything other than a .doc file a dialogue box will appear stating that they must only upload MS Word Document (when they click the ‘Upload CV’ button).

Does anyone know how I can evaluate the last 4 characters of the file name? Once the user has browsed to their CV on their PC the path & file name will appear in a text field called ‘CV’.

View 6 Replies (Posted: Dec 31, 2007, 08:29)

Sponsored Links:

Related Forum Messages For JavaScript category:
Foist Javascript Into Another Frame, And Evaluate It In The Target Context
I have an outer page and an inner iframe. The outer page calculates some
javascript, and wants the inner frame to run it. The inner frame should hit
a page on the same (private) web server, so this is not a cross-site
scripting attack. But I would prefer not to taint the target page with any
extra logic to do this. (I will if I must.)

The calling page has these elements:

<script src="/javascripts/prototype.js" type="text/javascript" />...
<span id='update_me'>yo2</span>
<iframe id='grinder' src='sample.html' >

So here's most of the page which the iframe hits:

<script src="/javascripts/prototype.js" type="text/javascript" />...
<body bgcolor='silver'>
<span id='update_me'>yo</span>

Note that both the outer and inner page have a span with the same ID.

This question will resemble a JavaScript FAQ - how to evaluate Javascript on
the fly, or how to reload a JS file. The answers on the web generally do not
transport the JS across a frame boundary, so they don't address the bug I
encountered, and I can't tell if prototype.js or IE is at fault.

The outer page calls Ajax goodies that generate some JS looking like this:

Element.update("update_me", "here I B");

The page sends that, as a string, into this JS (in application.js):

function update_grinder(sauce)
var grinder = $('grinder');

if (grinder)
var doc = grinder.contentDocument;
if (!doc) doc = grinder.document;
if (doc)
evaluate(doc, sauce);
document.write("your browser sucks");

So that contains enough logic to find the iframe's document, and it works
for Firefox, IE, Konqueror, and Opera. The code calls evaluate() with the
document where we need the evaluation context, and the string with our

Here's evaluate():

function evaluate(doc, sauce)
var s = doc.createElement('script');
//s.defer = true; // <-- no effect
s.text = sauce;
var body = doc.getElementsByTagName('body').item(0);

if (body)
body = doc.body;
if (body)

That creates a <scriptblock, sticks our string in as its contents, and
pushes the block to the end of our <bodytag. Now here's the bug:

Firefox updates the inner <span id='update_me'>, and IE updates the outer

If I remove the outer <span id='update_me'>, then IE simply can't find it
and throws an error. Even though it evaluates a script block clearly in the
context of the inner iframe.

I have tried calling the script from setTimeout, and from a button's onclick

Is there some way to fix (yet another) bug in IE? Or is this
a bug in prototype.js?

Posted: December 16th, 2006

View 15 Replies!   View Related
Too Many Characters In A JavaScript Function?
In IE, it looks like you can have to many characters in a javascript function.

The content of an entire html page is put into this function...

function updateTemplate(content) {
content=content.replace(/'/g, ''');
content=content.replace(/"/g, '"');
content=content.replace(/&lt;/g, '<');
content=content.replace(/&gt;/g, '>');
it seems to cut off the content after about 2060 characters. is that an IE thing or is there something wrong with my code. FF does it fine...

If it is an IE thing, is there anyway around it?

Posted: Nov 19, 2007, 22:45

View 6 Replies!   View Related
Unicode Characters In JavaScript Files
I have a custom object named #cdata-section, however I am unable to
access this object and get a run time "Illegal Character" javascript
error. my object looks like this:[i].body.#cdata-section

The pound sign is causing problems. How can I use this object in my
javascript source? Right now I'm trying something like this to escape
the pound sign:


however, that doesn't work, any ideas?

Posted: January 3rd, 2007

View 2 Replies!   View Related
Sequences Of Alphabetical Characters Using JavaScript
I've been looking at this for a while now and I just can't get my head around it. What i need to do is put together a program which allows the user to type in a sequence of letters and then tells the user how many times they have included the letter 'a' in their sequence. So far i have put this together but the output is totally wrong at the moment and it often either just says 1 or 4. Code:

Posted: 07-13-2006, 12:47 AM

View 7 Replies!   View Related
Adding Characters Like Character 253, 254 To Javascript Strings
My question is:

I'm adding character 253 to a javascript string this way:

var str = ''

str += 'a'
str += unescape('%FD');
str += 'b'

Is there another way to do this. Is there a function like: str += char(253)?

Posted: July 20th, 2005

View 1 Replies!   View Related
Valid Characters For JavaScript Variable Names
Just wondering if anyone can point me to a webpage detailing the valid characters that can be used for naming a JavaScript variable. I want to create a small 'extension library' for my non-javascript users here at work (who all seem to be squeamish when it comes to the language). I love how jQuery and Prototype have both used the '$' dollar sign, and since I use jQuery, I'm looking for another nice one character symbol to use. I realize that I could just test out a number of characters, but I'm posing this question to the JavaScript Sensi's of the world to give me advice about what characters (even if valid) would be a bad idea to use (perhaps for future integration with another popular library).

Posted: Nov 2 09 at 13:04

View 11 Replies!   View Related
Jquery :: Replace Newline Characters Using Javascript In IE8?
I've searched Stackoverflow for hours and hours, and nobody's solution works in Internet Explorer 8. I am provided with a plaintext document like this:


And I need to replace the newline characters (linebreaks, carriage returns, whatever you want to call them) with double linebreaks (<br/><br/>) to make the text look more normal. The nl2br function from jQuery convert line breaks to br (nl2br equivalent) works fine in most browsers. However, a client of mine uses IE8. Go ahead and try the nl2br function using IE8 (or a modern Internet Explorer set to IE8 mode); it doesn't work. Does anyone know why it doesn't work in IE8? And how to accomplish the goal?

Posted: Oct 7 11 at 22:24

View 1 Replies!   View Related
Include Javascript File In Another Javascript File
is it possible to use functions from javascript file A.js in javascript file B.js?

Posted: Jul 26, 2006, 04:03

View 5 Replies!   View Related
Problem Display Foreign Characters In Javascript Country/region Dropdown ...
Initially the form is loaded using ASP and HTML and the ü codes
display the characters correctly. I have the values stored in a
javascript array so that I can more easily and dynamically change the
state/region dropdown when the country changes. However, when my
javascript code tries to add the new option and print out new region
the literal value such as "Würrtemberg" is displayed instead of
the special character.

Can this be done in javascript?

Posted: October 16th, 2006

View 6 Replies!   View Related
JQuery :: Include Multiple Functions In A PHP File And Call Them Through Post Get In A Javascript File?
I want to call various functions made in PHP from my javascript file. Normally using we call a PHP file and and pass various values as post.


Posted: Jun 22 10 at 18:27

View 4 Replies!   View Related
Php File Outputting Javascript For Include As A JS File - Restrict So Its Not Opened In A Browser Window?
I'm storing configuration details in a database which I need to use in javascript. I'm accessing all this using php and instead of outputting all the details into inline javascript code on the main page I've instead created a php file that outputs content type javascript and refernce it in my main page as an external javascript file. I want to set it up so that it can't be viewed in a browser window i.e : <script type="text/javascript" src="phpFileThatDoesJS.php" ></script>

should work but typing in the browser shouldn't The thing is that I have to edit a script that for some oddball reason stores the username and password of a user in a javascript Object and outputs it within script tags. I have to set it up so that this is not viewable by a simple view source action. Thats why I thought of referencing it as an external javascript. Isnt there any htaccess tricks that I could use?

Posted: Jan 4 11 at 6:32

View 2 Replies!   View Related
Including A Javascript External File From The <body> Part Of An HTML File
I got an [object error] from IE 7.0.5730.11 when moving the <script
src="..." type="text/javascript" /tag from the <headpart to the
<bodysection of a HTML file.

Is not possibile to include Javascript code via <script src="..."
type="text/javascript" /from the <bodysection, instead from the
<headone? If yes, anyone has any idea of which the problem could be?
If not, how can I programmatically include a javascript external file
inside the <bodypart of a HTML file, for example, using Javascript
to some particular native functions?

Posted: September 26th, 2007

View 1 Replies!   View Related
Check File Name For Non-ASCII Characters?
I am using jQuery Uploadify to upload a file directly to S3. Everything works so far.What I need now is to validate the file via JS. To make sure that all characters are ASCII compatible.

Posted: Oct 8 11 at 11:21

View 1 Replies!   View Related
Disallow Characters Like %$& In A File Name In An Upload Form
i have a html/php form which let users upload pictures onto my server. the problem with it is, it says the picture has been uploaded but if the file name contains any of character apart from text (A-z) and numbers, the picture never shows up in the admin panel.

is there a way using ajax or jquery to disallow certain file names in the upload field of the html which uses these characters !@#$%^'&*()"?

how do i go on about this?

Posted: 08-30-2010, 06:24 PM

View 12 Replies!   View Related
Dynamically Loaded File And Non-ASCII Characters?
I have the following problem:

<script type="text/javascript">
<script type="text/javascript" src="Tst.js"></script>
<script type="text/javascript">


Posted: Mar 6 10 at 9:49

View 1 Replies!   View Related
AJAX :: Call To CSV File Returning For Certain Characters?
I have an CSV file with city names stored, some of these city name contain special charactors such as "S Paulo". I use an AJAX call to access the CSV as follows:


Alerted data returns the "?" symbol for the "A" charactor. I've tried saving the CSV as UTF-8 in Excel and setting the page meta tag to charset=UTF-8.

Posted: Nov 10 11 at 15:42

View 1 Replies!   View Related
Special Characters Are Not Being Read From A JSONP File Correctly?
I have some JSONP files which have data like: "ActiveLabel":"Site Survey Exact-Builtâ„¢" (notice the â„¢ char).

When I read the data from the file, by creating a script tag and using that to evaluate the JSONP file, then I get where â„¢ should be.

I tried setting charset="UTF-8" on the script tags I generate to load the JSONP, but that isn't helping.

what I can do to correct this?

Posted: Jan 20 11 at 1:55

View 1 Replies!   View Related
Encoding - Reading In Utf-8 File (XMLHttpRequest) Gives Bad European Characters?
can anyone help? I have small procedure to read in an UTF-8 file with javascript using XMLHttpRequest.. this file has european characters like miércoles sábado etc.. Notice the accents..

But when being read in .. the characters are all messed up.. I have checked the file and it is perfect.. it must be the procedure for reading in. heres an example i have file that contains, the file is perfect, it happens to be javascript but it doesn't matter.. any UTF-8 encoding file with special characters gives me the same issue

this.weekDays = new Array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo");but when returned and read by the procedure below it is like this (notice the funny characters in sabado and miercoles) this.weekDays = new Array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo");

return request.responseText;

Posted: Jun 20 09 at 6:26

View 2 Replies!   View Related
Jquery :: Using Non Standard Characters In File Causing Error In IE
In a JavaScript file, I am replacing english words with Turkish ones. Plugin works well in Chrome, firefox but it give exceptional error in IE. Characters causing error is "ö,ü".

$.fn.raty.defaults = {
hintList: ['bad', 'poor', 'regular', 'good', 'gorgeous']

For example, I replace 'poor' word with 'kötü' and IE says that "you have to specify ']' character".

I understand ö and ü characters damaging structure of JavaScript code flow.

Posted: Oct 13 11 at 15:39

View 1 Replies!   View Related
Use File From Signed Jar File In JavaScript Tag With PHP?
Technology: - We are using Apache Web Server, PHP, and Java Script on Windows XP. We have created a signed jar with the help of following steps.

Step 1:- Download NSS and NSPR tool
Step 2:- Setup the tool in C:


Posted: February 16th, 2009, 06:22 AM

View 3 Replies!   View Related
Save Exact Contents Of Web Form (including Special Characters) To File?
I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea contents with special characters, carriage returns, etc to a file?

Posted: March 6th, 2006

View 8 Replies!   View Related
i would like to evaluate a xpath expresion inside an iframe.

this is what i do :

1. find the iframe :

var f = document.getElementsByTagName('iframe');
2 evaluate the expresion :

var iterator = document.evaluate("//a", f[0], null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

var aElement = iterator.snapshotItem(0);

the problem is that this expresion gives me the anchor of the root document, not the anchor inside of the iframe.

Posted: Oct 14, 2006, 08:55

View 6 Replies!   View Related
Better Way To Evaluate Than Eval()?
I have a script that will loop through all the INPUT elements of a form; if the input is a submit it will disable the submit (or enable the submit, depending upon what is passed to the function.) I hate using eval() - I avoid it whenever I can! Is there a better way to dynamically process the ".disabled = 'true'/'false';" portion?


Posted: 11-03-2010, 02:36 PM

View 7 Replies!   View Related
CSS Within Javascript File?
Is it possible to use javascript to call css, as in having css related things in a js file, and have it being loaded at the same time as the script is running?A friend of mine was asking me and I told him I would check on it because I wasn't sure if you could have any css in a javascript file.

Posted: May 29, 2003, 17:57

View 2 Replies!   View Related
Copyright © 2005-08, All rights reserved