Skip to content Skip to sidebar Skip to footer

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.

  1. Create index.html file and paste the below.

<html><head><title></title></head><body><script>// your site sets a cookiedocument.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>
  1. Run a server python -m SimpleHTTPServer

  2. Open http://localhost:8000/

Post a Comment for "Append Javascript To Html Fields Using Through Javascript"