JavaScript Design Pattern for Text Input
-
I'm writing a simple game in JavaScrip that needs to occasionally ask the user for text input. I don't want to use the JavaScript prompt() method. I want to display an HTML textbox and have my JavaScript code display the textbox and wait for the user to fill it out and hit ENTER.This seems like the sort of pattern that someone would have devised, but my Google-Fu is weak on this. Any help would be appeciated. Not looking for external libraries if they can be avoided, although JQuery would be acceptable. Thanks!
-
Answer:
<input type="text" id="textbox" value="default"/>...var textbox = document.getElementById("textbox");textbox.onChange = function(){ /* do stuff with text here */ textbox.style.display = "none";};function thingThatAsksUserForInput() { /* other stuff ... */ textbox.style.display = "";}
DWRoelands at Ask.Metafilter.Com Visit the source
Other answers
So occasionally, you want to force a site to do the following: 1. display a text box 2. put users cursor into the text box 3. display a question or instructions to the user 4. they finish typing and hit enter 5. you close the question and instructions Is that it? Is there any validation of the input? If they mess up, do you do #5 above and then repeat at 1? Or should the text box respond somehow? Anything else? And do you or do you not want jQuery. And do you have any other libraries available, and do you have any limitations as far as what browsers this needs to work in? And lastly, it sounds like JavaScript is obligatory, right? So no JS-free effort is required, right?
artlung
Related Q & A:
- What's a good design pattern for bidirectional signals/events?Best solution by Programmers
- Why is Javascript called Javascript, if it has nothing to do with Java?Best solution by Stack Overflow
- Why is the last input printed twice in the text.txt?Best solution by dreamincode.net
- How to choose appropriate design pattern?Best solution by Stack Overflow
- How do you license an art design or pattern?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.