HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 24th, 2000, 01:34 PM
drbullpen drbullpen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 3 drbullpen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
After a 4 day crash course on HTML and Javascript, I have definitely hit a wall. I have created a simple form and I make calls to functions to validate input. But, as I have thrown in more and more validation or function calls, some of the functions are no longer performing correctly. Again, I have only a couple days of training (Book and online tutorials) so I apologize if I have created a mess.
Several things have occurred:

1. I want the cursor to automatically be placed in the first available input box in my form when the window opens. It worked in a small test, but now when called amongst the other functions, it does nothing.

2. I have a solid Soc Sec. check that seems to work (unless the user enters this: 1a2345678...this passes as true but I can live with this for right now...), but upon completion, it puts the cursor on the next field after the alert has told the user to change it.

3. My Zip check worked great originally, but now since I added more calls to functions, it evaluates everything as false. But when I output the value of zip, it passes thru exactly as I entered it, so I am assuming the values are ok, the evalution is just wrong right now.

4. I have found when I try to output to the user what they entered and they have left something blank, my programs outputs the users entries, THEN tells them "HEY YOU FORGOT TO ENTER SOMETHING..." I thought I had the calls in the right order when this happened.

5. Lastly, I need a quick explanation on how to output the value of radios. I can output all of the user input except when they check things...I get undefined values.

I will include my very "rough" code so it will be easier to determine whether I have violated some HTML or Javascript "rules." I am usually a self fixer, but I am "unexpectedly" leaving to play baseball in Puerto Rico in a week, so I have to hand this code over to someone else next Monday. I thought I would have months to iron these kinks out, but I now have only 3 working days left. Any help would be appreciated. Thanks in advance.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>New_Employee</title>


<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function placeFocus() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") | | (field.elements[i].type == "textarea") | | (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
}
}
}
}
// End -->
<!-- Begin
function checkFields() {
missinginfo = "";
if (document.Emp_form.employer.value == "") {
missinginfo += "n - Employer";
}
if (document.Emp_form.IDNum.value == "") {
missinginfo += "n - Emlpoyee Number";
}
if (document.Emp_form.SSNum.value == "") {
missinginfo += "n - Soc. Sec. Number";
}
if (document.Emp_form.Last_name.value == "") {
missinginfo += "n - Last Name";
}
if (document.Emp_form.First_name.value == "") {
missinginfo += "n - First Name";
}
if (document.Emp_form.Address.value == "") {
missinginfo += "n - Address";
}
if(document.Emp_form.City.value == "") {
missinginfo += "n - City";
}
if (document.Emp_form.State.value == "") {
missinginfo += "n - State";
}
if (document.Emp_form.Zip.value == "") {
missinginfo += "n - Zip Code";
}
if (document.Emp_form.Phone.value == "") {
missinginfo += "n - Phone";
}
if(document.Emp_form.Bonds_per_year.value == "") {
missinginfo += "n - Bonds per Year";
}
if(document.Emp_form.Deduction.value == "") {
missinginfo += "n - Deduction";
}
if (missinginfo != "") {
missinginfo ="_____________________________n" +
"You failed to correctly fill in your:n" +
missinginfo + "n_____________________________" +
"nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
// End -->
<!-- Begin
nextfield = "employer"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) { // handles keypress
// determines whether Netscape or Internet Explorer
k = (netscape) ? DnEvents.which : window.event.keyCode;
if (k == 13) { // enter key pressed
if (nextfield == 'done') return true; // submit, we finished all fields
else { // we're not done yet, send focus to next box
eval('document.Emp_form.' + nextfield + '.focus()');
return false;
}
}
}
document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
// end -->
<!-- begin
function SSN_check(form){
var valid2 = "0123456789";
var hyphencount2= 0;
SSNum_str = form.SSNum.value;
if (SSNum_str == "") {
alert("Please enter a 9 digit number for you social security number.");
return;
}
if (SSNum_str.length !=9) {
alert ("Your Social Security Number entry should be 9 digits.");
return;
}
for (var i=0; i < SSNum_str.length; i++) {
temp = "" + SSNum_str.substring(i, i+1);
if (temp == "-") hyphencount2++;
if (valid2.indexOf(temp) == "-1") {
alert("Invalid characters in the Soc. Sec. Number. Please try again.");
return false;
}
return true;
}}
// end -->
<!--
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code. Please try again.");
return false;
}
if ((hyphencount > 1) | | ((field.length==10) && ""+field.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again.");
return false;
}
}
return true;
}
// end -->
<!-- Begin
function doit()
{
var agree=confirm("Company Name: "
+ document.Emp_form.employer.value
+ "nEmployee Number: " + document.Emp_form.IDNum.value
+ "nSoc Sec Number: " + document.Emp_form.SSNum.value
+ "nLast Name: " + document.Emp_form.Last_name.value
+ "nFirst Name: " + document.Emp_form.First_name.value
+ "nAddress: " + document.Emp_form.Address.value
+ "nAddress2: " + document.Emp_form.Address2.value
+ "nCity: " + document.Emp_form.City.value
+ "nState: " + document.Emp_form.State.value
+ "nZip Code: " + document.Emp_form.Zip.value
+ "nPhone: " + document.Emp_form.Phone.value
+ "nPhone2: " + document.Emp_form.Phone2.value
+ "nService Fee: " + document.Emp_form.fee.value
+ "nBonds per Year: " + document.Emp_form.Bonds_per_year.value
+ "nBond Size " + document.Emp_form.Size.value
+ "nBond Series: " + document.Emp_form.Series.value
+ "nBond Code: " + document.Emp_form.Code.value
+ "nDeduction Amount: " + document.Emp_form.Deduction.value
+ "nReady To Submit?");
if (agree)
return true;
else
history.go(0);
}
// End -->
</script>
</head>

<body>
<a href="C:my documentsmain_view.html" target="index">HOME</a>
<form OnLoad="placeFocus()" name = "Emp_form" onSubmit="return checkFields()"><pre><b>
Company Name: <input type= "text" name ="employer" size=40 maxlength=20 value = "" onFocus="nextfield ='IDNum';">
Employee Number: <input type= "text" name ="IDNum" size=9 maxlength=9 value = "" onFocus="nextfield ='SSNum';">
Employee Status:</b> <input type=radio name ="status" value="A" checked> Active <input type=radio name ="status" value="I" > Inactive <input type=radio name ="status" value="B" > Barely Breathing<b>
Soc. Sec. Number: <input type= "text" name ="SSNum" size=9 maxlength=9 value = "" onChange = "SSN_check(this.form)" onFocus="nextfield ='Last_name';">
Last Name: <input type= "text" name ="Last_name" size=20 maxlength=20 value = "" onFocus="nextfield ='First_name';">
First Name: <input type= "text" name ="First_name" size=20 maxlength=20 value = "" onFocus="nextfield ='Address';">
Address: <input type= "text" name ="Address" size=30 maxlength=30 value = "" onFocus="nextfield ='Address2';"> Address2: <input type= "text" name ="Address2" size=30 maxlength=30 value = "" onFocus="nextfield ='City';">
City: <input type= "text" name ="City" size=12 maxlength=20 value = "" onFocus="nextfield ='State';"> State: <select id="State" name="State" size="1" onFocus="nextfield ='Zip';">
<option value="Al">Alabama (AL)
<option value="AK">Alaska (AK)
<option value="AZ">Arizona (AZ)
<option value="AR">Arkansas (AR)
<option value="CA">California (CA)
<option value="CO">Colorado (CO)
<option value="CT">Conneticut (CT)
<option value="DE">Delaware (DE)
<option value="DC">Dist. of Colombia (DC)
<option value="FL">Lorida (FL)
<option value="GA">Georgis (GA)
<option value="HI">Hawaii (HI)
<option value="ID">Idaho (ID)
<option value="IL">Illinois (IL)
<option value="IN">Indiana (IN)
<option value="IA">Iowa (IA)
<option value="KS">Kansas (KS)
<option value="KY">Kentucky (KY)
<option value="LA">Louisiana (LA)
<option value="ME">Maine (ME)
<option value="MD">Maryland (MD)
<option value="MA">Massachusettes (MA)
<option value="MI">Michigan (MI)
<option value="MN">Minnesota (MN)
<option value="MS">Mississippi (MS)
<option value="MO">Missouri (MO)
<option value="MT">Montana (MT)
<option value="NE">Nebraska (NE)
<option value="NV">Nevada (NV)
<option value="NH">New Hamshire (NH)
<option value="NJ">New Jersey (NJ)
<option value="NM">New Mexico (NM)
<option value="NY">New York (NY)
<option value="NC">North Carolina (NC)
<option value="ND">North Dakota (ND)
<option value="OH">Ohio (OH)
<option value="OK">Oklahoma (OK)
<option value="OR">Oregon (OR)
<option value="PA">Pennsylvania (PA)
<option value="PR">Puerto Rico (PR)
<option value="RI">Rhode Island (RI)
<option value="SC">South Carolina (SC)
<option value="SD">South Dakota (SD)
<option value="TN">Tennessee (TN)
<option value="TX">Texas (TX)
<option value="UT">Utah (UT)
<option value="VT">Vermont (VT)
<option value="VA">Virginia (VA)
<option value="WA">Washington (WA)
<option value="WV">West Virginia (WV)
<option value="WI">Wisconsin (WI)
<option value="WY">Wyoming (WY )
</select> Zip:<input type= "text" name ="Zip" size=10 maxlength=10 value = "" onChange="validateZIP(this.form)" onFocus="nextfield ='Phone';">
Phone: <input type= "text" name ="Phone" size=15 maxlength=15 value = "" onFocus="nextfield ='Phone2';"> Phone 2:<input type= "text" name ="Phone2" size=15 maxlength=15 value = "" onFocus="nextfield ='Bonds_per_year';">
Service Fee:</b> <input type=radio name ="fee" value="Y" checked>Yes <input type=radio name ="fee" value="N" >No
<b>PayDays per Year:</b> <input type=radio name ="Paydays" value="W" onFocus="nextfield ='Bonds_per_year';">52 <input type=radio name ="Paydays" value="BW1">26 <input type=radio name ="Paydays" value="BW2">24 <input type=radio name ="Paydays" value="M">12
<b>Bonds per Year: <input type= "text" name ="Bonds_per_year" size=3 maxlength=3 onFocus="nextfield ='Deduction';">
Bond Size:</b> <input type=radio name ="Size" value="fifty" onFocus="nextfield ='Series';"> $50 <input type=radio name ="Size" value="seventy_five" > $75 <input type=radio name ="Size" value="hundred"> $100 <input type=radio name ="Size" value="two_hundred" > $200 <input type=radio name ="Size" value="five_hundred"> $500 <input type=radio name ="Size" value="one_thousand" > $1000
<b> Bond Series:</b> <input type=radio name ="Series" value="EE" onFocus="nextfield ='Deduction';" > EE-Series <input type=radio name ="Series" value="II" > I-Series
<B>CODE:</b> <input type=radio name ="Code" value="C" onFocus="nextfield ='Deduction';"> Co-Owner <input type=radio name ="Code" value="B" > POD <input type=radio name ="Code" value="X"> Neither</b>
<b>Deduction Amount: <input type= "text" name ="Deduction" size=10 maxlength=10 onFocus="nextfield ='done';" >
<input type = reset value = "RESET FORM"> <input type = submit name = "done" VALUE= "Submit" onclick="doit()">

</pre>
</body>
</html>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Form Validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway