javasript work good in firefox not in ie
-
var n=''
str=document.getElementById("attach").value
//temp = str.split('\\');
m=str.lastIndexOf("\\")
for(i=m+1;i<str.length;i++)>
{
n = n + str[i];
// alert
}
alert
document.getElementById("name").innerHTML = n;
alert(document.getElementById("name").innerHTML);this code is work in firefox while not work in ie given undefine. why? anybody can tell me what the reason. :-D
I will do my best? Integrated Solutions, Bikaner (Raj.), India
-
var n=''
str=document.getElementById("attach").value
//temp = str.split('\\');
m=str.lastIndexOf("\\")
for(i=m+1;i<str.length;i++)>
{
n = n + str[i];
// alert
}
alert
document.getElementById("name").innerHTML = n;
alert(document.getElementById("name").innerHTML);this code is work in firefox while not work in ie given undefine. why? anybody can tell me what the reason. :-D
I will do my best? Integrated Solutions, Bikaner (Raj.), India
Why don't you use the Javascript
substr
function rather than incrementally adding the characters to the variable? It takes the form:string.substr(start, n);
where start is the starting character of the substring and n is the number of characters to return after this. Change your code to:var n="";
str=document.getElementById("attach").value;
m=str.lastIndexOf("\\");
m++; //Increment the position of the last \\ so it is not included in the variable n.n = str.substr(m, str.length-m);
document.getElementById("name").innerHTML = n;alert(document.getElementById("name").innerHTML);
Tried in FF, Opera and IE and works in all. Regards, --Perspx
"I've got my kids brainwashed: You don't use Google, and you don't use an iPod." - Steve Ballmer
"Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen an angry penguin charging at them in excess of 100mph." - Linus Torvalds -
Why don't you use the Javascript
substr
function rather than incrementally adding the characters to the variable? It takes the form:string.substr(start, n);
where start is the starting character of the substring and n is the number of characters to return after this. Change your code to:var n="";
str=document.getElementById("attach").value;
m=str.lastIndexOf("\\");
m++; //Increment the position of the last \\ so it is not included in the variable n.n = str.substr(m, str.length-m);
document.getElementById("name").innerHTML = n;alert(document.getElementById("name").innerHTML);
Tried in FF, Opera and IE and works in all. Regards, --Perspx
"I've got my kids brainwashed: You don't use Google, and you don't use an iPod." - Steve Ballmer
"Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen an angry penguin charging at them in excess of 100mph." - Linus Torvaldsya i know it very well that its work and i am also using split function of javascript to do this work and its working very well but i would like to know that (like you read in my question) that why this code is not work in ie while in w3schools.com says which i use function is work in both browser but why this one is not work. please tell me this what't the problem in my code. thanks for reply. :-D
I will do my best? Integrated Solutions, Bikaner (Raj.), India
-
ya i know it very well that its work and i am also using split function of javascript to do this work and its working very well but i would like to know that (like you read in my question) that why this code is not work in ie while in w3schools.com says which i use function is work in both browser but why this one is not work. please tell me this what't the problem in my code. thanks for reply. :-D
I will do my best? Integrated Solutions, Bikaner (Raj.), India
The reason it doesn't work in IE is because it doesnt like you doing:
string[i]
to return a character; try something like:var s = "hello";
alert(s[0]);
and try it in IE and FF and note that it returns undefined in IE. The JavaScript standards are slightly different in IE and Mozilla-based browsers so this is why. If you wanted to return a character, the safe option would be:
var character = string.substr(i, 1);
where i is the character you want to return from string. Regards, --Perspx"I've got my kids brainwashed: You don't use Google, and you don't use an iPod." - Steve Ballmer
"Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen an angry penguin charging at them in excess of 100mph." - Linus Torvalds -
var n=''
str=document.getElementById("attach").value
//temp = str.split('\\');
m=str.lastIndexOf("\\")
for(i=m+1;i<str.length;i++)>
{
n = n + str[i];
// alert
}
alert
document.getElementById("name").innerHTML = n;
alert(document.getElementById("name").innerHTML);this code is work in firefox while not work in ie given undefine. why? anybody can tell me what the reason. :-D
I will do my best? Integrated Solutions, Bikaner (Raj.), India