InnerHTML not working in firefox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amitdotchauhan
    New Member
    • Jan 2010
    • 5

    InnerHTML not working in firefox?

    see this page.

    http://www.mochinews.c om/Guest/Guesthome.aspx

    i have written a function replacedivs() to swap div content
    which works fine in opera/IE/Chrome

    Only fails in Firefox.

    Any comments?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you are using eval() for getting a node?

    from what I can see (I didn’t check the whole code) this code should be updated to a more safe and modern version.

    Comment

    • amitdotchauhan
      New Member
      • Jan 2010
      • 5

      #3
      Hi Dormilich,

      Thanks for reply.
      Function already use the eval.
      which is as copied below.
      main page calls this function which is there in script.js

      Code:
      function ReplaceDivs(source,destination)
      {
      var p,q;
      p=eval('document.getElementById("'+ source +'")');
      q=eval('document.getElementById("'+ destination+'")');
      destination.innerHTML=source.innerHTML;
      source.innerHTML='';
      
      }
      i thought i'd never get a answer!!

      :D
      Thanks,
      Amit
      Last edited by Dormilich; Mar 2 '10, 06:42 AM. Reason: Please use [code] tags when posting code

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Code:
        function ReplaceDivs(source,destination)
        {
        destination.innerHTML=source.innerHTML;
        source.innerHTML='';
        }
        does the same (provided you pass the correct values). (what use is a variable, if you don’t use it?)

        Code:
        // with test
        function ReplaceDivs(source, destination)
        {
            if (!(source instanceof HTMLDivElement) || !(destination instanceof HTMLDivElement)) {
                throw new TypeError("Source or Destination is not a <div>.");
            }
            destination.innerHTML = source.innerHTML;
            source.innerHTML = '';
        }

        Comment

        • amitdotchauhan
          New Member
          • Jan 2010
          • 5

          #5
          P.S.issue is that the function is not called in firefox i tried to put alert in that function
          which is called in IE/Chrome/Opera but not in FF

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            FF correctly claims the parameters not to be existant.
            Code:
            function ReplaceDivs(source_ID, destination_ID)
            {
                source = document.getElementById(source_ID);
                destination = document.getElemenById(destination_ID);
                destination.innerHTML = source.innerHTML;
                source.innerHTML = '';
            }
            call
            Code:
            ReplaceDivs("tempFemaleProfile", "FemaleProfile");

            Comment

            • amitdotchauhan
              New Member
              • Jan 2010
              • 5

              #7
              Hi Dormilich,

              You are right.so silli mistake, I made now I realize!
              No wonder you are genius!
              I was passing element rather than element name.
              Also there was issue with parameter name I guess.source & destination are standard names. cant be used like that I guess so.
              Your JS knowledge is awesome.
              Some questions now :
              1.May I know source of "source instanceof HTMLDivElement" terms where its found very commonly?
              2.what are the other types? Mail me in private if you may.


              So final solution i implemented was
              Code:
               
              // with test
              function ReplaceDivs(s,d)
              {
              var p,q;
              p=eval('document.getElementById("'+ s +'")');
              q=eval('document.getElementById("'+ d +'")');
              q.innerHTML=p.innerHTML;
              p.innerHTML='';
              }
              and
              Code:
               ReplaceDivs("tempFemaleProfile", "FemaleProfile");

              Closing this problem for now.
              Thanks again :)
              Last edited by amitdotchauhan; Mar 3 '10, 06:57 PM. Reason: use [code] for putting code

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by amitdotchauhan
                Some questions now :
                1.May I know source of "source instanceof HTMLDivElement" terms where its found very commonly?
                2.what are the other types? Mail me in private if you may.
                2. no need to
                1. I don’t think it’s very common. but you can find the "types" (= Interfaces) here and here

                Comment

                Working...