PDA

View Full Version : Textbox with submit button



sebas1
Jul 11th, 2010, 10:14 PM
I'm new with HTML...I'm building a site for my boss and it's going well. I just have one thing I still havent figured out. My boss would like to have something like a textbox and submit button, when you type a name in the textbox and click submit the phone # of that person appears in another textbox. Is this possible to do. any help on how I could start would be appriciated.

Rowsdower!
Jul 11th, 2010, 10:53 PM
I'm new with HTML...I'm building a site for my boss and it's going well. I just have one thing I still havent figured out. My boss would like to have something like a textbox and submit button, when you type a name in the textbox and click submit the phone # of that person appears in another textbox. Is this possible to do. any help on how I could start would be appriciated.

HTML alone will not accomplish this. You have the option to use javascript, use a server-side language (like PHP, ASP, or the like), or use both together.

You would pick your approach depending on what exactly your're trying to do. If you have a pre-determined, never/rarely changing list of users and their phone numbers then this can all be achieved via javascript without much of a learning curve.

If your list will change frequently then you would probably need to develop a database and use a server-side language to search that database and return the correct answer to the page. You could do that with or without javascript as a helper - that would be a matter of choice.

I'm guessing this is probably the former (relatively static list) so I would recommend studying up a bit on javascript. W3schools (http://www.w3schools.com/) is pretty good for beginners.

You will need to work the script out so that it does the following:
1) on submit of the form (when you click on the submit button) the script retrieves the value of the textbox.
2) the value of the text box is checked against the list of stored names (stored in a javascript array).
3) a. if a match is found, get the associated phone number from the list of phone numbers (stored in another javascript array, ordered in the same order as the names such that the first user has the first phone number, the second user has the second phone number, and so on).
b. insert a second text box into the page (or, if one will already be there, simply select that text box) and set the value of that text box to the value of the name-matched phone number.
4) if no match is found, notify the user that their name search returned no results (this could be done with an alert() or by inserting an error message using similar methods as you use for inserting a phone number).


Overall this is not a difficult project. It's maybe a little advanced for a first-run at javascript but if you take it easy and read up between steps you should be able to nail this.