i want to call onclick function in another function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NavinVerma
    New Member
    • Apr 2010
    • 2

    #1

    i want to call onclick function in another function

    My code is


    Code:
    <script language="javascript">
           document.write("<select id=\"num\" onchange=\"selected()\">");
           document.write("<option>");
           for(i=1;i<=10;i++)
           document.write("<option value="+i+">"+i);
           document.write("</select>");
           function selected()
           {
             var j;
             j=document.getElementById("num").value;
             document.write("Table Name <input type='text' id='tname'  /><br>")
             for(i=1;i<=j;i++)
               {
                  document.write("Attribute"+i+"<input type='text' id='attri"+i+"' />");
                  document.write("<select name=\"datatype\"><option>int<option>varchar<option>char<option>boolean<option>date</select><br>");
               }
               document.write("<input type=\"button\" value=\"Ok\" onclick=\"submit\" />");
           }
           function submit()
           {
               document.write("hello");
           }
           
          </script>
    problem in this code is function submit is not running it throws some error i couldn't find it.

    tell me this code is possible some how
    Last edited by gits; Apr 30 '10, 09:50 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you cannot use document.write( ) when the page is rendered already - this destroys the DOM ... you might create the button before and hide it ... in the function you could unhide it and then the onclick of the button will work - but you would even need to refer the form and call its submit method:
    Code:
    onclick="form_ref.submit();"
    kind regards

    Comment

    Working...