Href Links in Dynamic table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • webmaniac

    Href Links in Dynamic table

    Hi,

    I am creating a table dynamically in javascript.

    All is fine but when I try to put any ahref link on the cell its not
    taking it. I am doing like that.
    var rowHead1 = document.create Element('TR');
    var CellHead1 = document.create Element('TD');
    var text1 = "<a href=http://www.google.com> " + someVariable + "</a>
    var cellHeadText1 = document.create TextNode(text1) ;
    CellHead1.appen dChild(cellHead Text1);

    But somehow when I run this example.
    It shows like that in Table cell.
    <a href=http://www.google.com> abc</a>

    Its not converting it into a Link.

    Any Idea, what's going wrong here.
  • Erwin Moller

    #2
    Re: Href Links in Dynamic table

    webmaniac schreef:
    Hi,
    >
    I am creating a table dynamically in javascript.
    >
    All is fine but when I try to put any ahref link on the cell its not
    taking it. I am doing like that.
    var rowHead1 = document.create Element('TR');
    var CellHead1 = document.create Element('TD');
    var text1 = "<a href=http://www.google.com> " + someVariable + "</a>
    var cellHeadText1 = document.create TextNode(text1) ;
    CellHead1.appen dChild(cellHead Text1);
    >
    But somehow when I run this example.
    It shows like that in Table cell.
    <a href=http://www.google.com> abc</a>
    >
    Its not converting it into a Link.
    >
    Any Idea, what's going wrong here.
    Hi,

    Not sure, but shouldn't you at least quote the hyperlink properly?
    Like this:
    var text1 = "<a href='http://www.google.com' >" + someVariable + "</a>";

    Regards,
    Erwin Moller


    --
    "There are two ways of constructing a software design: One way is to
    make it so simple that there are obviously no deficiencies, and the
    other way is to make it so complicated that there are no obvious
    deficiencies. The first method is far more difficult."
    -- C.A.R. Hoare

    Comment

    • webmaniac

      #3
      Re: Href Links in Dynamic table

      On Nov 12, 12:40 pm, Erwin Moller
      <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
      webmaniac schreef:
      >
      >
      >
      Hi,
      >
      I am creating a table dynamically in javascript.
      >
      All is fine but when I try to put any ahref link on the cell its not
      taking it. I am doing like that.
      var rowHead1 = document.create Element('TR');
      var CellHead1 = document.create Element('TD');
      var text1 = "<a href=http://www.google.com> " + someVariable + "</a>
      var cellHeadText1 = document.create TextNode(text1) ;
      CellHead1.appen dChild(cellHead Text1);
      >
      But somehow when I run this example.
      It shows like that in Table cell.
      <a href=http://www.google.com> abc</a>
      >
      Its not converting it into a Link.
      >
      Any Idea, what's going wrong here.
      >
      Hi,
      >
      Not sure, but shouldn't you at least quote the hyperlink properly?
      Like this:
      var text1 = "<a href='http://www.google.com' >" + someVariable + "</a>";
      >
      Regards,
      Erwin Moller
      >
      --
      "There are two ways of constructing a software design: One way is to
      make it so simple that there are obviously no deficiencies, and the
      other way is to make it so complicated that there are no obvious
      deficiencies. The first method is far more difficult."
      -- C.A.R. Hoare
      I tried that too, but it still dont work.
      I dont know, where I am getting wrong.

      Comment

      • Gregor Kofler

        #4
        Re: Href Links in Dynamic table

        webmaniac meinte:
        >>var text1 = "<a href=http://www.google.com> " + someVariable + "</a>
        >>var cellHeadText1 = document.create TextNode(text1) ;
        I tried that too, but it still dont work.
        I dont know, where I am getting wrong.
        Why should it? Anchors are not text nodes. Something like

        var a = document.create Element("a");
        a.href = "...";
        a.appendChild(d ocument.createT extNode("whatev er");
        CellHead1.appen dChild(a);

        Your "approach" requires to fill the (non-standard) innerHTML property
        of CellHead1.

        Gregor

        Comment

        • Erwin Moller

          #5
          Re: Href Links in Dynamic table

          webmaniac schreef:
          On Nov 12, 12:40 pm, Erwin Moller
          <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
          >webmaniac schreef:
          >>
          >>
          >>
          >>Hi,
          >>I am creating a table dynamically in javascript.
          >>All is fine but when I try to put any ahref link on the cell its not
          >>taking it. I am doing like that.
          >>var rowHead1 = document.create Element('TR');
          >>var CellHead1 = document.create Element('TD');
          >>var text1 = "<a href=http://www.google.com> " + someVariable + "</a>
          >>var cellHeadText1 = document.create TextNode(text1) ;
          >> CellHead1.appen dChild(cellHead Text1);
          >>But somehow when I run this example.
          >>It shows like that in Table cell.
          >><a href=http://www.google.com> abc</a>
          >>Its not converting it into a Link.
          >>Any Idea, what's going wrong here.
          >Hi,
          >>
          >Not sure, but shouldn't you at least quote the hyperlink properly?
          >Like this:
          >var text1 = "<a href='http://www.google.com' >" + someVariable + "</a>";
          >>
          >Regards,
          >Erwin Moller
          >>
          >--
          >"There are two ways of constructing a software design: One way is to
          >make it so simple that there are obviously no deficiencies, and the
          >other way is to make it so complicated that there are no obvious
          >deficiencies . The first method is far more difficult."
          >-- C.A.R. Hoare
          >
          I tried that too, but it still dont work.
          I dont know, where I am getting wrong.
          Ahum, sorry.

          You know this feeling you are knew how something worked but totally
          cannot retieve it?
          I just had that great experience again, but a little googling helped.

          You need to create the hyperlink element first ('a') and append that.
          this is the trick:
          var aElem = document.create Element('a');

          Here is a sample from:
          Javascript is capable of appending child elements to the DOM of a web page dynamically. This quick answer demonstrates one way to append a element to a . How to append a hyperl…


          function appendLink()
          {
          //Get the element that we want to append to
          var divEl = document.getEle mentById('link_ div');
          //Create the new <a>
          var aElem = document.create Element('a');
          aElem.href="htt p://www.google.com" ;
          //Create a text node to hold the text of the <a>
          var aElemTN = document.create TextNode('link to Google.com');
          //Append the <atext node to the <aelement
          aElem.appendChi ld(aElemTN);
          //Append the new link to the existing <div>
          divEl.appendChi ld(aElem);
          }


          That should help. :P

          Regards,
          Erwin Moller


          --
          "There are two ways of constructing a software design: One way is to
          make it so simple that there are obviously no deficiencies, and the
          other way is to make it so complicated that there are no obvious
          deficiencies. The first method is far more difficult."
          -- C.A.R. Hoare

          Comment

          • webmaniac

            #6
            Re: Href Links in Dynamic table

            On Nov 12, 2:16 pm, Erwin Moller
            <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
            webmaniac schreef:
            >
            >
            >
            On Nov 12, 12:40 pm, Erwin Moller
            <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
            webmaniac schreef:
            >
            >Hi,
            >I am creating a table dynamically in javascript.
            >All is fine but when I try to put any ahref link on the cell its not
            >taking it. I am doing like that.
            >var rowHead1 = document.create Element('TR');
            >var CellHead1 = document.create Element('TD');
            >var text1 = "<a href=http://www.google.com> " + someVariable + "</a>
            >var cellHeadText1 = document.create TextNode(text1) ;
            > CellHead1.appen dChild(cellHead Text1);
            >But somehow when I run this example.
            >It shows like that in Table cell.
            ><a href=http://www.google.com> abc</a>
            >Its not converting it into a Link.
            >Any Idea, what's going wrong here.
            Hi,
            >
            Not sure, but shouldn't you at least quote the hyperlink properly?
            Like this:
            var text1 = "<a href='http://www.google.com' >" + someVariable + "</a>";
            >
            Regards,
            Erwin Moller
            >
            --
            "There are two ways of constructing a software design: One way is to
            make it so simple that there are obviously no deficiencies, and the
            other way is to make it so complicated that there are no obvious
            deficiencies. The first method is far more difficult."
            -- C.A.R. Hoare
            >
            I tried that too, but it still dont work.
            I dont know, where I am getting wrong.
            >
            Ahum, sorry.
            >
            You know this feeling you are knew how something worked but totally
            cannot retieve it?
            I just had that great experience again, but a little googling helped.
            >
            You need to create the hyperlink element first ('a') and append that.
            this is the trick:
            var aElem = document.create Element('a');
            >
            Here is a sample from:http://acsummer.wordpress.com/2007/1...ynamically-add...
            >
            function appendLink()
            {
            //Get the element that we want to append to
            var divEl = document.getEle mentById('link_ div');
            //Create the new <a>
            var aElem = document.create Element('a');
            aElem.href="htt p://www.google.com" ;
            //Create a text node to hold the text of the <a>
            var aElemTN = document.create TextNode('link to Google.com');
            //Append the <atext node to the <aelement
            aElem.appendChi ld(aElemTN);
            //Append the new link to the existing <div>
            divEl.appendChi ld(aElem);
            }
            >
            That should help. :P
            >
            Regards,
            Erwin Moller
            >
            --
            "There are two ways of constructing a software design: One way is to
            make it so simple that there are obviously no deficiencies, and the
            other way is to make it so complicated that there are no obvious
            deficiencies. The first method is far more difficult."
            -- C.A.R. Hoare
            Thanks Everyone, It worked.

            Comment

            Working...