Web Page Generator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Death Slaught
    Top Contributor
    • Aug 2007
    • 1137

    #16
    Thanks for the info and the JavaScript lessons! I always enjoy posting here because everything you say makes sense (most of the time).

    Thanks,
    {\_/}
    (' . ')
    (")[DEATH](")
    (")(")
    PS - @ hsriat Thanks I got bored ^_^

    Comment

    • Death Slaught
      Top Contributor
      • Aug 2007
      • 1137

      #17
      I have the second "section" completed I just have to make a few CSS adjustments but I was curious if there was an easier (but still user friendly) to accomplish what I'm doing with nodes.

      [HTML]
      <div id="holder"><te xtarea id="t0" rows="20" cols="50"></textarea></div>
      [/HTML]

      This creates the nodes when the user clicks the button.
      [CODE=javascript] function newSection() {
      var paragraphNode = document.create Element("textar ea");
      if (!document.getE lementById("t1" )) {
      paragraphNode.s etAttribute("id ", "t1");
      paragraphNode.s etAttribute("ro ws", "20");
      paragraphNode.s etAttribute("co ls", "50");
      }
      if (document.getEl ementById("t1") ) {
      paragraphNode.s etAttribute("id ", "t2");
      paragraphNode.s etAttribute("ro ws", "20");
      paragraphNode.s etAttribute("co ls", "50");
      }
      if (document.getEl ementById("t2") ) {
      paragraphNode.s etAttribute("id ", "t3");
      paragraphNode.s etAttribute("ro ws", "20");
      paragraphNode.s etAttribute("co ls", "50");
      }
      if (document.getEl ementById("t3") ) {
      paragraphNode.s etAttribute("id ", "t4");
      paragraphNode.s etAttribute("ro ws", "20");
      paragraphNode.s etAttribute("co ls", "50");
      }
      if (document.getEl ementById("t4") ) {
      paragraphNode.s etAttribute("id ", "t5");
      paragraphNode.s etAttribute("ro ws", "20");
      paragraphNode.s etAttribute("co ls", "50");
      }
      if (document.getEl ementById("t5") ) {
      alert("We're sorry you have used all of your space.");
      return;
      }
      var emptyNode = document.create TextNode("");
      paragraphNode.a ppendChild(empt yNode);
      var nodePlacement = document.getEle mentById("holde r");
      nodePlacement.a ppendChild(para graphNode);
      }
      [/CODE]

      This is the code that retrieves the users input.
      [CODE=javascript]
      code+="<div id='wrapper'>";
      code+="<p>" + mainContents + "</p>";
      if (document.getEl ementById("t1") ) {
      code+="<p>" + document.getEle mentById("t1"). value + "</p>";
      }
      if (document.getEl ementById("t2") ) {
      code+="<p>" + document.getEle mentById("t2"). value + "</p>";
      }
      if (document.getEl ementById("t3") ) {
      code+="<p>" + document.getEle mentById("t3"). value + "</p>";
      }
      if (document.getEl ementById("t4") ) {
      code+="<p>" + document.getEle mentById("t4"). value + "</p>";
      }
      if (document.getEl ementById("t5") ) {
      code+="<p>" + document.getEle mentById("t5"). value + "</p>";
      }
      code+="</div>";
      [/CODE]

      I could have the user input the paragraph tags them selves but I prefer this method. (The Complete code is attached).

      Thanks,
      {\_/}
      (' . ')
      (")[DEATH](")
      (")(")
      PS - I haven't switched the onclick to JavaScript yet but I'm doing that right now (thanks again).
      Attached Files

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #18
        Originally posted by Death Slaught
        I have the second "section" completed I just have to make a few CSS adjustments but I was curious if there was an easier (but still user friendly) to accomplish what I'm doing with nodes.
        Use a variable to store the current number, so you can remove the repetitive code:
        [CODE=javascript] // currTextAreaNum contains the current number of textareas
        function newSection() {
        var paragraphNode = document.create Element("textar ea");
        currTextAreaNum ++;
        if (currTextAreaNu m == 5) {
        alert("We're sorry you have used all of your space.");
        return;
        }
        paragraphNode.s etAttribute("id ", "t"+currTextAre aNum);
        paragraphNode.s etAttribute("ro ws", "20");
        paragraphNode.s etAttribute("co ls", "50");

        var emptyNode = document.create TextNode("");
        paragraphNode.a ppendChild(empt yNode);
        var nodePlacement = document.getEle mentById("holde r");
        nodePlacement.a ppendChild(para graphNode);
        }
        [/CODE]

        Comment

        • Death Slaught
          Top Contributor
          • Aug 2007
          • 1137

          #19
          Awesome thanks! You make life so much more simple.

          Thanks,
          {\_/}
          (' . ')
          (")[DEATH](")
          (")(")

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #20
            No problem. I think you should add a delete/remove button to allow users to remove nodes too.

            Comment

            Working...