开发者

How to Create a Form Dynamically Via Javascript

开发者 https://www.devze.com 2023-03-26 02:36 出处:网络
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 creat

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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消