php - Retrieving data from form made in javascript -
i have uploaded fiddle of js code (http://jsfiddle.net/3mcm2/), @ bottom of way in calling js in php document. in order run script, remove php code comments bottom. wanted add see how outputting in php. also, above last comments 3 lines of comments in .js file, there see php echoing better understand how looks.
/* following in .js file: (see bottom of script part of in php file) */ var f = document.createelement("form"); f.setattribute('method', "get"); f.setattribute('action', "index.php"); var category = (function () { var categorycount = 0; function elem(tag) { // shortcut return document.createelement(tag); } function text(str) { // shortcut return document.createtextnode(str); } function category(node) { var self = this; this.categoryid = ++categorycount; // make add button this.addbutton = elem('button'); this.addbutton.appendchild(text('add textbox')); this.addbutton.addeventlistener('click', function () { self.addtextbox(); }); // make wrapper this.wrapper = elem('section'); this.wrapper.setattribute('id', 'cat'+this.categoryid); this.wrapper.appendchild(this.addbutton); // make textboxes this.textboxes = []; this.addtextbox(); // append document if (node) { this.append(node); } } category.prototype.addtextbox = function () { var e = document.createelement("input"); e.setattribute('name', 'cat-'+this.categoryid+'-textbox[]'); f.appendchild(e); // each textbox supposed added form... this.textboxes.push(e); this.wrapper.insertbefore(e, this.addbutton); }; category.prototype.append = function (node) { return node.appendchild(this.wrapper); }; return category; }()); var s = document.createelement("input"); //input element, submit button s.setattribute('type',"submit"); s.setattribute('value',"submit"); f.appendchild(s); //var cat1 = new category(document.body); //var cat2 = new category(document.body); //document.getelementsbytagname('body')[0].appendchild(f);
the above comment see script doing , 3 lines not in .js file. following comments part of in php file, pretty outputting above comments:
$counter = 0; echo '<script type="text/javascript" src="js/categories.js"></script>'; foreach ($catarr $category) { $counter++; echo 'do<script>var cat'.$counter.' = new category(document.body);</script>'; } echo "<script>document.getelementsbytagname('body')[0].appendchild(f);</script>";
my problem form created in js, not delivering data. php page going index.php index.php? question mark, , not of textbox variables following question mark. reason, form not finding textboxes created or names. please me out.
this code:
var cat1 = new category(document.body); function category(node) { var self = this; this.categoryid = ++categorycount; // make add button this.addbutton = elem('button'); this.addbutton.appendchild(text('add textbox')); this.addbutton.addeventlistener('click', function () { self.addtextbox(); }); // make wrapper this.wrapper = elem('section'); this.wrapper.setattribute('id', 'cat'+this.categoryid); this.wrapper.appendchild(this.addbutton); // make textboxes this.textboxes = []; this.addtextbox(); // append document if (node) { this.appendchild(node); } }
appends input text boxes body
, not form
, when press submit no data being passed
fiddle working code: http://jsfiddle.net/5h8pv/1/
Comments
Post a Comment