Click to See Complete Forum and Search --> : Javascript Telephone Book help
Zujan
12-09-2002, 09:12 AM
Hi there, I have just started with js and could use the help of someone with some js experience. I have a project due and I basically haven't been taught what I need to know.
I am trying to create a simple telephone book in javascript. The goal of this script is to have the user enter a first name, last name and phone number into 3 different text boxes. These 3 entries must be validated for length, to make sure text was entered, that the telephone number has the correct amount of digits, and that there are no numbers in the names. Then when the enter button is clicked they are to be displayed in a textarea below. The other thing is that these 3 options have to be stored in either separate arrays or a multidimensional array. I have no idea how to link up arrays to text boxes and how to call everything into the text area once the enter is clicked? This is supposed to be a simple code but I cannot find a similar one anywhere including my book. This is due at the end of the week. If anyone could start me out with the code I would need to link textareas and text boxes with arrays I can probablly figure out the validation code. Any other help and I would be very greatful. Thanks!
Ryan
Zujan
12-10-2002, 07:15 AM
I do understand how that works, my problem is this. I only need one set of text boxes for the user to enter the 3 pieces of information. So everytime some info is entered, the user can click an enter button, it will store in an array and also be displayed in a <textarea> below. Once the enter button is clicked, the text boxes should be cleared, the info just entered is visible within the textarea, and another batch of information could be entered. I am not sure of:
1) How do you make the info typed in the text boxes appear in the textarea once the enter button is clicked?
2) How do you have the info typed in each text box save into an array? Would I just create var lastName = new Array()
... and then if that is true, do I just name the text box the same as the array?
3) I know I need to use onclick, just not sure exactly at what point
here is the basic code I have so far:
<body bgcolor="red" text="white">
<script language="JavaScript">
var firstnameArray = new Array();
var lastnameArray = new Array();
var phonenumberArray = new Array();
</script>
<h3>New person:</h3>
<form name="Address">
<table>
<tr>
<td>First name:</td>
<td><input type="text" name="firstname" size="30"></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="text" name="lastname" size="30"></td>
</tr>
<tr>
<td>Telephone #:</td>
<td><input type="text" name="phonenum" size="30"></td>
</tr>
</table>
<br>
<input type="button" name="enter" value="Submit!" >
<input type="reset" value="Reset Form" name="reset1">
<br><br>
<textarea rows="15" cols="70" name="textarea" onclick=document.write(firstnameArray)>
</textarea>
</form>
</body>
Zujan
12-10-2002, 07:52 PM
Thank you for that helpful start. Below is what I have now, and it is still pretty buggy. If anyone can assist me to getting to my eventual finished product I will be thankful.
<body bgcolor="red" text="white">
<script language="JavaScript">
var phoneBook[phoneBook.length] = new Array
(
document.Address.firstname.value,
document.Address.lastname.value,
document.Address.phonenum.value
);
<h3>New person:</h3>
<form name="Address">
<table>
<tr>
<td>First name:</td>
<td><input type="text" name="firstname" size="30" onclick="></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="text" name="lastname" size="30"></td>
</tr>
<tr>
<td>Telephone #:</td>
<td><input type="text" name="phonenum" size="30"></td>
</tr>
</table>
<br>
<input type="button" name="enter" value="Submit!" >
<input type="reset" value="Reset Form" name="reset1">
<br><br>
<textarea rows="15" cols="70" name="textarea" onclick=document.write(document.Address.textarea.value
= "\\n"
+ document.Address.firstname.value
+ ", "
+ document.Address.lastname.value + " Phone: "
+ document.Address.phonenum.value; )>
</textarea>
</form>
</script>
</body>
</html>
Check the top of this page for the end result desired. Any help is very appreciated! Thank you
Zujan
12-11-2002, 06:55 AM
Cool, well thanks for your help Dave. Anyone else who could help me out could benefit greatly. Yes this project is due in 2 days. Anyone who can give me the code needed I will owe big time. I am an e-commerce web designer, trying to learn some basic javascript. If you need some flash, 3d studio max, sql, or just want a web site done I will hook you up, but I do need a code to accomplish what I have listed above. Anyone? If you would rather email it then post it here, contact me at rbetts33@hotmail.com Thanks everyone. O, and Dave, I see those tutorials are from the Wrox book, I don't think I'll read that again, too many things wrong with the examples they offer, not very helpful at all.