469,337 Members | 6,124 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,337 developers. It's quick & easy.

i want to call onclick function in another function

My code is


Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.        document.write("<select id=\"num\" onchange=\"selected()\">");
  3.        document.write("<option>");
  4.        for(i=1;i<=10;i++)
  5.        document.write("<option value="+i+">"+i);
  6.        document.write("</select>");
  7.        function selected()
  8.        {
  9.          var j;
  10.          j=document.getElementById("num").value;
  11.          document.write("Table Name <input type='text' id='tname'  /><br>")
  12.          for(i=1;i<=j;i++)
  13.            {
  14.               document.write("Attribute"+i+"<input type='text' id='attri"+i+"' />");
  15.               document.write("<select name=\"datatype\"><option>int<option>varchar<option>char<option>boolean<option>date</select><br>");
  16.            }
  17.            document.write("<input type=\"button\" value=\"Ok\" onclick=\"submit\" />");
  18.        }
  19.        function submit()
  20.        {
  21.            document.write("hello");
  22.        }
  23.  
  24.       </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
Apr 30 '10 #1
1 1411
gits
5,390 Expert Mod 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. onclick="form_ref.submit();"
kind regards
Apr 30 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Nx | last post: by
7 posts views Thread by extremerep | last post: by
1 post views Thread by finerrecliner | last post: by
9 posts views Thread by IchBin | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.