1 Replies - 338 Views - Last Post: 29 February 2012 - 09:09 AM

#1 TinkerTailor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 10-January 12

"Alert if file extension not an option" isn't working in C

Posted 29 February 2012 - 08:54 AM

My Javascript function to this test is as follows. This works in both Firefox and IE when I open the site in either browser. When I run this in Chrome it does not. I am thinking this is because in Chrome there is no text field showing the value of the text document like with Firefox and IE.

function testResumeValid(id) {
	var pass = false;
	var val = $(id).value;
	if(val.substring(val.length-3) == "doc") {
		pass = true;
	} else if(val.substring(val.length-4) == "docx") {
		pass = true;
	} else if(val.substring(val.length-3) == "pdf") {
		pass == true;
	}
	
	return pass;
}
function warnResumeInvalid(id) {
	if(!testResumeValid(id)) {
		alert('That is an invalid file type.');
	}
}


And here it is implemented in the page.

<p>
        <label for="filResume">Attach resume</label><br />
	<input type="file" id="filResume" name="FUUploader"  onblur="warnResumeInvalid('filResume')" />              
        <br />
	<span id="uploader">Word or PDF Documents Only</span>
</p>



Should this be able to check the file extension is valid in Chrome?

function $(id){
	var element = document.getElementById(id);
	if( element == null )
		alert( 'Programmer error: ' + id + ' does not exist.' );
	return element;
}


I'm not sure if it's necessary, but that code explains the $(id) call.

Is This A Good Question/Topic? 0
  • +

Replies To: "Alert if file extension not an option" isn't working in C

#2 fastlane85  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 17
  • Joined: 13-March 10

Re: "Alert if file extension not an option" isn't working in C

Posted 29 February 2012 - 09:09 AM

Glad you clarified the "$" function as I thought you were using jQuery originally.

I'm not sure why but I was only able to get your code to work in Google Chrome by changing the "onblur" to "onchange", after this change the code works in FF 10.0.2, IE9 and Chrome so maybe it has something to do with Chrome's implementation of the file input type...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1