My sites Aweber registration forms are getting a lot of spam. I was told to create the forms dynamically via javascript after page has rendered or via clicking button. How would I create and render a form via javascript?
-
1what do you mean by creating a form dynamically?Mohammad Faisal– Mohammad Faisal2011-08-06 05:16:46 +00:00Commented Aug 6, 2011 at 5:16
-
6I'm not sure why this was downvoted so much or closed. Dynamic form generation via javascript means building the DOM rather than serving it via HTML.recursive– recursive2011-08-06 05:22:33 +00:00Commented Aug 6, 2011 at 5:22
-
15He means creating a form after the page has been rendered. Why was this closed?Sparkup– Sparkup2011-08-06 05:24:09 +00:00Commented Aug 6, 2011 at 5:24
-
I wonder, is there a library for this, similar to the (PHP) Drupal Form API?Ideogram– Ideogram2014-07-27 10:04:48 +00:00Commented Jul 27, 2014 at 10:04
Add a comment
|
1 Answer
some thing as follows ::
Add this After the body tag
This is a rough sketch, you will need to modify it according to your needs.
<script>
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"submit.php");
var i = document.createElement("input"); //input element, text
i.setAttribute('type',"text");
i.setAttribute('name',"username");
var s = document.createElement("input"); //input element, Submit button
s.setAttribute('type',"submit");
s.setAttribute('value',"Submit");
f.appendChild(i);
f.appendChild(s);
//and some more input elements here
//and dont forget to add a submit button
document.getElementsByTagName('body')[0].appendChild(f);
</script>
2 Comments
Jeremy
How would you add a button (along side submit) to remove the respective form?
peter jalton
For some reason, the submit button for this code does not work in IE Edge, or previous versions of IE. Puzzled as to why