Append Javascript To Html Fields Using Through Javascript
I'm currently trying to create a form dynamically through javascript after looking at this post. Everything is going smoothly until when I attempt to insert javascript to the input
Solution 1:
Here is an example.
- Create
index.html
file and paste the below.
<html>
<head>
<title></title>
</head>
<body>
<script>
// your site sets a cookie
document.cookie="username=John Doe";
my_form = document.createElement('form');
my_tb = document.createElement('input');
my_tb.value = document.cookie;
my_form.appendChild(my_tb);
document.body.appendChild(my_form);
alert(my_tb.value);
</script>
</body>
</html>
Run a server
python -m SimpleHTTPServer
Open
http://localhost:8000/
Post a Comment for "Append Javascript To Html Fields Using Through Javascript"