Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic Form Creation and submission in OOP
    primarykey
    data
    text
    <p>I'm trying to create a class to dynamically create a form and then submit the form. it's a simple class but now I have lost my way.</p> <pre><code> var creathtml=function(){ this.createform=function(o,title){ var openingtag="&lt;form action='#' class='form-horizontal well' onSubmit='this.submitform'&gt;&lt;fieldset&gt;&lt;legend&gt;"+title+"&lt;/legend&gt;"; var fields=""; for (var i=0; i&lt;o.length; i++) { if(o[i].type=='input') { fields+="&lt;div class='control-group'&gt;&lt;label class='control-label' for='"+o[i].id+"'&gt;"+o[i].label+"&lt;/label&gt;&lt;div class='controls'&gt;&lt;input type='"+o[i].subtype+"' id='"+o[i].id+"' class='"+o[i].class+"'&gt;&lt;/div&gt;&lt;/div&gt;"; } if(o[i].type=='button') { fields+="&lt;div class='control-group'&gt;&lt;div class='controls'&gt;&lt;button type='"+o[i].subtype+"' id='"+o[i].id+"' class='"+o[i].class+"'&gt;"+title+"&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;"; } } var closingtag="&lt;/fieldset&gt;&lt;/form&gt;"; $(body).html (openingtag+fields+closingtag; }; this.submitform=function() { console.log('mnmnmnmn'); return false; } } </code></pre> <p><strong>Usage</strong></p> <pre><code> var obj= new creathtml; var h=obj.createform([ {'type':'input','subtype':'input','name':'Wow','label':'Item Name','id':'itmname','class':''}, {'type':'input','subtype':'input','name':'hello','label':'Item Code','id':'hello','class':''}, {'type':'input','subtype':'input','name':'hello','label':'Item Code','id':'hello2','class':''}, {'type':'button','subtype':'submit','name':'submit','label':'Null','id':'submit','class':'btn btn-primary'} ],'Create New Items'); </code></pre> <p>i have successfully created the HTML and populated on DOM. but don't know how to detect the form submission or create the submit method for this particular class?</p> <p>this is my first time trying in javascript OOP , so if doing wrong please suggest the right way if possible</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload