File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how do I take out the extension in javascript :( urgent .... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how do I take out the extension in javascript :( urgent ...." Watch "how do I take out the extension in javascript :( urgent ...." New topic
Author

how do I take out the extension in javascript :( urgent ....

mou haj
Ranch Hand

Joined: Sep 12, 2001
Posts: 81
I upload a file ... but ill only allow to upload .txt or .csv extension files.... now after submitting i come to know the extension but with javascript how will I take out the extension... is their some thing like stringtokeniser in javascript
say I have H:\java\tutor\information\inprogress.html how will I take out the extension using javascript.Please help its very very urgent
anand chawla
Ranch Hand

Joined: Oct 19, 2000
Posts: 91
Well u can use substring() and indexof()
that would solve the problem
mou haj
Ranch Hand

Joined: Sep 12, 2001
Posts: 81
but foe substring ill have to give the starting point and the offset but here i dont how the length befor the extension by some mechanism ill have to specify to take out the alphabets after the .
anand chawla
Ranch Hand

Joined: Oct 19, 2000
Posts: 91
Hi,
Well u can use indexOf to check for . that is extension
and then use it in substring..
its simple just give a try.
for example..
String text="line.js";
int x=Integer.parseInt(text.indexOf(".");
String sub=text.substring(x);
thats it...it will solve the prob..
Syam Veerakumar
Ranch Hand

Joined: Sep 20, 2001
Posts: 49
U can use this to verify extension in the front end itself.
<script language ="javascript">
function verify_Extension() {
var t = document.FormName.FormAttribute.value;
var z=t.substring(t.length,t.length -4);
if (z == ".txt" | | z == ".csv" )
{ return true; }
else
{ alert("Only TXT's or CSV's are allowed\n");
return false; }
}
</script>
//inside HTML
<form name="formName" onSubmit="return verify_Extension()">
Originally posted by mou haj:
I upload a file ... but ill only allow to upload .txt or .csv extension files.... now after submitting i come to know the extension but with javascript how will I take out the extension... is their some thing like stringtokeniser in javascript
say I have H:\java\tutor\information\inprogress.html how will I take out the extension using javascript.Please help its very very urgent


A Quitter Never Wins<br />A Winner Never Quits
Mou
Greenhorn

Joined: Jul 11, 2001
Posts: 3
thanx a lot shyam and anand its working fine ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do I take out the extension in javascript :( urgent ....