Click to See Complete Forum and Search --> : [Object] Printing for no reason and won't tab


Zujan
12-12-2002, 11:20 PM
Ok This is the script revised. I still need to figure out how to:

1) Keep special characters (!@#$%^) Out of the first and last name text boxes

2) How can I make it so that no numbers whatsoever can be in the first or last names?

3) How to just clear the text boxes when clear is clicked and leave the info int he textarea alone

4) Also if possible how to sort the info in the textarea

<script language="JavaScript">
<!--
var LastName=new Array();
var FirstName=new Array();
var PhNumber=new Array();
var PhNumber1=new Array();
var PhNumber2=new Array();

function postPhoneList()
// this will be called by FormCheck to enter info into the Textarea

{
document.myPhoneBook.myList.value = "";
for(loopCounter=0;loopCounter<LastName.length; loopCounter=loopCounter+1)
{
document.myPhoneBook.myList.value=
document.myPhoneBook.myList.value +
FirstName[loopCounter] + " " +
LastName[loopCounter] + " : " + "(" +
PhNumber[loopCounter]+ ")" +
PhNumber1[loopCounter]+ "-" +
PhNumber2[loopCounter]+ "\n";
}
}

function FormCheck()
// this will check all values entered into the text boxes

{
var telephone=document.myPhoneBook.phone1.value
var telephone1=document.myPhoneBook.phone2.value;
var telephone2=document.myPhoneBook.phone3.value;
var last=document.myPhoneBook.lastName.value;
var first=document.myPhoneBook.firstName.value;
var validity="true";
var temp= LastName.length;
var size1=telephone.length
var size2=telephone1.length
var size3=telephone2.length
if (first == "")
{
alert("You have left the first name blank. Please enter your first name!");
document.myPhoneBook.firstName.focus();
validity= "false";
}

else if (!(isNaN(first.charAt())))
{
alert("Your first name must be letters only!");
document.myPhoneBook.firstName.focus();
validity="false"
}

else if (last == "")
{
alert("You have left the last name blank. Please enter your last name!");
document.myPhoneBook.lastName.focus();
validity= "false";
}

else if (!(isNaN(last.charAt())))
{
alert("Your last name must be letters only!");
document.myPhoneBook.lastName.focus();
validity="false"
}

else if (telephone== "")
{
alert("Please complete the area code field with 3 numbers. Try again!");
document.myPhoneBook.phone1.focus();
validity= "false";
}

else if (size1 < 3)
{
alert("Please enter 3 numbers for the postal code. Try again!");
document.myPhoneBook.phone1.focus();
validity="false"
}

else if (isNaN(telephone.charAt()))
{
alert("Please enter numbers only in the telephone fields. Try again!");
document.myPhoneBook.phone1.focus();
validity="false";
}


else if (telephone1== "")
{
alert("Please complete the second phone number field with 3 numbers. Try again!");
document.myPhoneBook.phone2.focus();
validity= "false";
}

else if (size2 < 3)
{
alert("Please enter 3 numbers for the second part of the phone number. Try again!");
document.myPhoneBook.phone2.focus();
validity="false"
}

else if (isNaN(telephone1.charAt()))
{
alert("Please enter numbers only in the telephone fields. Try again!");
document.myPhoneBook.phone2.focus();
validity="false";
}


else if (telephone2== "")
{
alert("Please complete the third phone number field with 4 numbers. Try again!");
document.myPhoneBook.phone3.focus();
validity= "false";
}


else if (size3 < 4)
{
alert("Please enter 4 numbers for the last part of the phone number. Try again!");
document.myPhoneBook.phone3.focus();
validity="false";
}

else if (isNaN(telephone2.charAt()))
{
alert("Please enter numbers only in the telephone fields. Try again!");
document.myPhoneBook.phone3.focus();
validity="false";
}


else if (validity=="true")
{
LastName[temp]=last ;
FirstName[temp]=first;
PhNumber[temp]=telephone;
PhNumber1[temp]=telephone1;
PhNumber2[temp]=telephone2;
document.myPhoneBook.firstName.focus();

postPhoneList();

}

}

function tab(obj,OBJ,n)
// this will cause the curser to tab automatically while entering the phone #'s

{
if (obj.value.length >= n)
{
OBJ.focus();
}
}

//-->
</SCRIPT>

</head>

<body background="C:\WINDOWS\Profiles\Ryan\My Documents\Images\Metal1.bmp" script language="javascript">

<h1><u><font color="white" face="arial">My Telephone Book</font></u></h1>

<img src="movingrule.gif">
<form name=myPhoneBook method="get">
<br><br>
<table>

<tr>
<td><h3><font color="white" face="arial">First name:</font>&nbsp;&nbsp;&nbsp;
<input type="text" maxLength="25" name="firstName"></h3></td>
</tr>
<tr>
<td><h3><font color="white" face="arial">Last name:</font>&nbsp;&nbsp;&nbsp;
<input type="text" maxLength="30" name="lastName"></h3></td>
</tr>
<tr>
<td><h3><font color="white" face="arial">Telephone #:</font>
<input type="text" name="phone1" size="3" onKeyup="tab(phone1,phone2,'3')" maxlength="3">
<input type="text" name="phone2" size="3" onKeyup="tab(phone2,phone3,'3')" maxlength="3">
<input type="text" name="phone3" size="4" maxlength="4"></h3></td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>

<tr align="center">

<td><input onclick="FormCheck()"; type="button" name="button" value="Add">&nbsp;
<input type="reset" value="Clear">
</td>
</tr>

<tr>
<td colspan="4"><textarea cols="70" name="myList" rows="15"></textarea>
</td>
</tr>

</table>
</form>
</script>

ShrineDesigns
12-13-2002, 12:47 AM
use this instead of your 'autotab'
with this you can omit the maxlength attribute

<html>
<head>
<title></title>
<script language="JavaScript" type="text/JavaScript">
<!--
function tab(obj,OBJ,n){
if (obj.value.length >= n){
OBJ.focus();
}
}
//-->
</script>
</head>
<body>
<form action="" method="get" name="myForm">
<input name="phone1" type="text" onKeyUp="tab(phone1,phone2,'3')">
<input name="phone2" type="text" onKeyUp="tab(phone2,phone3,'3')">
<input name="phone3" type="text" onKeyUp="tab(phone3,'','4')">
</form>
</body>
</html>

Zujan
12-13-2002, 01:08 AM
Awesome, thank you so much for that. Tabbing Problem Solved!!! :)

Now:

1) How can I get just the information within the text boxes to clear when the clear button is clicked and not the info in the text area?

2) How can I prevent users from using special characters such as ^&^&)(_*_* in the name and phone number textboxes?

3) and if anyone has any idea how I can sort the items in the textarea alphabetically, that would be very cool as well.

Thanks for the help so far, you rock!

Zujan
12-13-2002, 02:34 PM
Hey there, does anyone know this at all? I need to know within the hour if possible. Let me know