Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. javasript work good in firefox not in ie

javasript work good in firefox not in ie

Scheduled Pinned Locked Moved ASP.NET
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UD IA
    wrote on last edited by
    #1

    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

    P L 2 Replies Last reply
    0
    • U UD IA

      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

      P Offline
      P Offline
      Perspx
      wrote on last edited by
      #2

      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

      U 1 Reply Last reply
      0
      • P Perspx

        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

        U Offline
        U Offline
        UD IA
        wrote on last edited by
        #3

        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

        P 1 Reply Last reply
        0
        • U UD IA

          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

          P Offline
          P Offline
          Perspx
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • U UD IA

            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

            L Offline
            L Offline
            leckey 0
            wrote on last edited by
            #5

            ...

            Blog link to be reinstated at a later date.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups