View Single Post
  #4 (permalink)  
Old Aug 28th, 2007, 14:02
QuikFrozen QuikFrozen is offline
Up'n'Coming Member
Join Date: Aug 2006
Location: Peru
Age: 21
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Substring Problem

Ok man, here's a small javascript I just wrote with a little html so you realize what's happening :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Backslash</tilte>
<script type="text/javascript">
function doCrop(text){
var file=document.getElementById("myfile").value;
if(file!=""){
crop(file,text);
}
else{
alert("must select a file");
}
}
function crop(file,newText){
var slash;
var temp=file.indexOf("\\");
//get the last backslash
while(temp>=0){
slash=temp+1;
temp=file.indexOf("\\",slash);
}
if(slash>=0){
//here you can do whatever you want to the path
file=file.substring(0,slash)+newText;
alert(file);
}
else{
alert("bad file format");
}
}
</script>
</head>
<body>
<input type="file" id="myfile" />
<input type="button" name="mybutton" value="Go" onclick="doCrop('main.jsp');"/>
</body>
</html>
Reply With Quote