locked
java script RRS feed

  • Question

  • User1125372096 posted

    <script type="text/javascript" language="javascript">
           function createDivId() {
               alert("hgh");
               var divTag = document.createElement("div");
               divTag.id = "div1";
               divTag.setAttribute("align", "center");
               divTag.style.margin = "0px auto";
               divTag.innerHTML = "This <b>HTML Div tag</b> is created using Javascript DOM dynamically.";
               divTag.innerHTML ='<div id="showdiv>'
                <table>
                       <tr>
                         <td>
                         "<br><input type='text' name='mytext'+i>"
                         </td>
                          
                         <td>
                          "<br><input type='text' name='mytext'+i>"
                         </td>
                       
                       
                       
                       </tr>
                </table>
                 <div>   
                       
               
               document.body.appendChild(divTag);
               document.getElementById('showdiv').appendChild(divTag);
               
           }
       </script>

    not working


    Wednesday, December 1, 2010 4:37 AM

Answers

  • User1643008609 posted

    Hi Friend,

    I am not getting what is the value of  var "i" which is not passed in function-

    Done some modifications try this -

    <html>
    <head>
    <script type="text/javascript" language="javascript">
           function createDivId() {
               alert("hgh");
               var divTag = document.createElement("div");
               divTag.id = "div1";
               divTag.setAttribute("align", "center");
               divTag.style.margin = "0px auto";
               divTag.innerHTML = "This <b>HTML Div tag</b> is created using Javascript DOM dynamically.";
               divTag.innerHTML +='<div id="showdiv>';
                divTag.innerHTML +='<table>'

                       divTag.innerHTML +='<tr>'
                         divTag.innerHTML +="<td><br><input type='text' name='mytext'+i></td><td><br><input type='text' name='mytext'+i></td></tr>"
                divTag.innerHTML +='</table>'
                 divTag.innerHTML +='<div>';   
                       
               
               document.body.appendChild(divTag);
               //document.getElementById('showdiv').appendChild(divTag);
               
           }
       </script>
    </head>
    <body>
    <script>
    createDivId();
    </script>
    </body>
    </html>

    Hope this will help

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 1, 2010 5:12 AM

All replies

  • User-1659704165 posted

    Either Use Javascript Debugger

    http://aspnetlive.blogspot.com/2010/02/debugging-java-script-in-visual-studio.html

    OR

    Better use Jquery

    Wednesday, December 1, 2010 5:04 AM
  • User1643008609 posted

    Hi Friend,

    I am not getting what is the value of  var "i" which is not passed in function-

    Done some modifications try this -

    <html>
    <head>
    <script type="text/javascript" language="javascript">
           function createDivId() {
               alert("hgh");
               var divTag = document.createElement("div");
               divTag.id = "div1";
               divTag.setAttribute("align", "center");
               divTag.style.margin = "0px auto";
               divTag.innerHTML = "This <b>HTML Div tag</b> is created using Javascript DOM dynamically.";
               divTag.innerHTML +='<div id="showdiv>';
                divTag.innerHTML +='<table>'

                       divTag.innerHTML +='<tr>'
                         divTag.innerHTML +="<td><br><input type='text' name='mytext'+i></td><td><br><input type='text' name='mytext'+i></td></tr>"
                divTag.innerHTML +='</table>'
                 divTag.innerHTML +='<div>';   
                       
               
               document.body.appendChild(divTag);
               //document.getElementById('showdiv').appendChild(divTag);
               
           }
       </script>
    </head>
    <body>
    <script>
    createDivId();
    </script>
    </body>
    </html>

    Hope this will help

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 1, 2010 5:12 AM
  • User-1552632442 posted

    Hi,

        are you looking for this..

    <script type="text/javascript" language="javascript">
           function createDivId() {
               alert("hgh");
               var divTag = document.createElement("div");
               divTag.id = "div1";
               divTag.setAttribute("align", "center");
               divTag.style.margin = "0px auto";
               divTag.innerHTML = "This <b>HTML Div tag</b> is created using Javascript DOM dynamically.";
               divTag.innerHTML +='<div id="showdiv">'
                + '<table>'
                +       '<tr>'
                +           '<td>'
                +               '<br><input type="text" name="mytext"+i>'
                +           '</td>'
                +           '<td>'
                +               '<br><input type="text" name="mytext"+i>'
                +           '</td>'
                +       '</tr>'
                +'</table>'
                +'<div>';
                       
               document.body.appendChild(divTag);
               document.getElementById('showdiv').appendChild(divTag);
           }
       </script>


    Hope this helps,

    Anilkumar M.S 

    Wednesday, December 1, 2010 5:15 AM