Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
mou haj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well u can use substring() and indexof()
that would solve the problem
 
mou haj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Mou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx a lot shyam and anand its working fine ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic