Add javascript function to div
Hello,
I have this task...
- <a href="#" id="btn_1">trigger form</a>
- <div id="myform"></div>
and custom jaascript function:
- function generateForm() {
- var form = document.createElement("form");
- form.setAttribute('method',"get"); // form method
- form.setAttribute('action',""); // form action url
- form.setAttribute('name',"frmName"); // form name
- form.setAttribute('id',"frmId"); // form ID
-
- var inputCtrl = document.createElement("input");
- inputCtrl.type = "text";
- inputCtrl.name = "data";
- inputCtrl.setAttribute('id',"txt");
-
- var inputSubmit = document.createElement("input");
- inputSubmit.type = "submit";
- inputSubmit.name = "submit";
- inputSubmit.setAttribute('id',"sbmt");
- inputSubmit.value = "Submit";
-
- /* To bind created input control with created from */
- form.appendChild(inputCtrl);
- form.appendChild(inputSubmit);
-
- /* To bind created form with current document body */
- document.body.appendChild(form);
- }
The task is, when clicked the link ( #bnt_1 ) to display the form in DIV ( #myform )
Thе code below works, but not what I want.
- $('#btn_1').click(function() {
- generateForm();
- });
I want the form to be in DIV.
Is there any suggestion?
Thanks!