Anonymous
Not logged in
Talk
Contributions
Create account
Log in
Publication Station
Search
Editing
Courses/Design & Technique-Essential Web Design/Q2/Example/Form
From Publication Station
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Receive user text input in a form input. Use it in the variable firstName Example: http://publicationstation.wdka.hro.nl/go-student/examples/user-txt-input.html Code: <source lang="html4strict"> <!DOCTYPE html> <html><head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <style> form{width: 50%;} input{padding: 6px; width:50%; border: 2px solid #ccc; margin-top: 1em; color: #000;} input:focus{border: 2px solid yellow; background-color: rgba(0, 0, 0, 0.75); color: white; font-weight: bold;} input[type="submit"]{font-weight: bold; width: auto; } input[type="submit"]:focus{ color: yellow; background-color: rgba(0, 0, 0, 0.75);} #instruction{display: none; } </style> </head> <body> <h1 id="question">Tell me you name...</h1> <form id="greeting"> <input name="firstName" id="firstName" required="" placeholder="Your first name" type="text"><br> <input value="Send" type="submit"> </form> <h2 id="instruction">Now <span class="userName"></span>, I want you to walk 10 steps away from where you are now.</h2> <script> var firstName; // variable that will store user name $("form#greeting").submit(function(event){ console.log( $('#firstName').val() ); firstName = $('#firstName').val(); event.preventDefault(); $("#firstName").val(''); //clean input#firstName $('form, #question').css('display', 'none'); //hide form $('#instruction').css('display', 'block'); //show instruction $('span.userName').text(firstName); //Add name to span.userName }) </script> </body></html> </source>
Summary:
Please note that all contributions to Publication Station are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Publication Station:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Main navigation
Main page
Printmaking Studio
Print Studio
Dig. Publishing Studio
Namespaces
Grafiwiki
Random Page
Log in
Wiki tools
Wiki tools
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs