home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2719
Discussions: 186,607, Posts: 2,227,057, Members: 230,242
Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
Old September 15th, 2008, 01:23 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Sep 2008
Posts: 2
Exclamation
Java script Help, Please throw me a life vest

I'm writing a mailing list using javascripts to validate that the first, last name and email address has some information in them, nothing specific just some info. The problem I'm having is when you dont fill in these three fields it suppose to redirect with a popup stating that one of three fields are'nt filled out and allow the user to attempt to fill out again. Bare with me I'm as green as it comes with this so I'm trying to learn as I can. Your help is appreciated, thanks and God Bless !!!!

<html>

<head>

<title>Kudler Customer Mailing List</title>

<!-- Nakia Cumming -->
<!-- WEB/406 Web Programming II-->
<!-- Professor Nancy Cosgrove -->

<script language="javascript">
<!--
function formCheck(formobj){

var fieldRequired = Array("FirstName", "LastName","eMail Address");

var fieldDescription = Array("First Name", "Last Name","eMail");

// Below is my error message

var alertMsg = "Please complete these fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
exit();
return false;
}
}




var count=0;






//This redirects where needed
function redirect()
{
if(!count)
location.href = 'Error.html';
else
location.href = 'Confirm.html';


}

//-->
</SCRIPT>


</head>

<body>


<body bgcolor="#000110"></body>



<center><table width="850" bgcolor="#c69b96"></center>

<tr>
<td>

<H1>Kudler Mailing list</H1><!-- Header -->
<H3>In order to recieve online coupons please fill out the form below.</H3>

<hr size="10" width="100%" noshade>

<form name="Customer" onsubmit="return validate(this);" form action="javascript:redirect();"><!-- Form -->

First Name:<br> <INPUT size=35 name=FirstName><br>
Last Name:<br> <INPUT size=35 name=LastName><br>
Address:<br> <INPUT size=35 name=Address><br>
City:<br> <INPUT size=35 name=City><br>
State: <br>
<select name="States">
<option value="" SELECTED></option><!-- Select Box -->
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select><br>

Zip: <br><INPUT size=35 name=Zip><br>
Home Phone: <br><INPUT size=35 name="HomePhone"><br>
eMail Address: <br><INPUT size=35 name="eMail Address"><br>

<hr size="10" width="100%" noshade>

<INPUT type=submit value="Submit Form"> <!-- Buttons -->
<INPUT type=reset value="Clear Fields" name=clear><br><br>


</td>
</tr>
</table>

</body>
</html>

nacummings is offline   Reply With Quote
TechIMO.com Ads - Login or register for less ads.
How many errors does your computer have?

You no longer need to guess! This free stability scan and registry cleaner download will give you a complete diagnosis of your Windows registry, identifying errors and conflicts.

FREE instant scan


Guest, Register Free! to remove this ad and get your tech support questions answered in minutes!
Old September 17th, 2008, 05:25 AM     #2 (permalink)
Senior Member
 
Join Date: May 2003
Location: Aus, Gold Coast :)
Posts: 793
Send a message via ICQ to exally
first of all, in the future please use code tags. secondly. Instead of having the message length as the determining factor use a simple bool, true or false, and set it if it doesn't work. also I believe you don't require exit();

In saying that where u have validate(this) in the form declaration, it might help if u changed it to formCheck(this).

exally is offline   Reply With Quote
Old September 22nd, 2008, 07:54 PM     #3 (permalink)
Junior Member
 
Join Date: Sep 2008
Posts: 2
Exclamation

Quote:
Originally Posted by exally View Post
first of all, in the future please use code tags. secondly. Instead of having the message length as the determining factor use a simple bool, true or false, and set it if it doesn't work. also I believe you don't require exit();

In saying that where u have validate(this) in the form declaration, it might help if u changed it to formCheck(this).



THANKS A BUNCH, from your advise I finally got it too work but I have to use the message length for this design. But now I wrote my cookies but I'm having trouble with these as well. Here is what I have so far, I'm definitely not good with cookies far from it, so please some simple language on this one....You fellows are the CODE WARRIORS, I call upon your help!!!!


<script language="javascript">
<!--
function formCheck(formobj){

var fieldRequired = Array("FirstName", "LastName","eMail Address");

var fieldDescription = Array("First Name", "Last Name","eMail");

// Below is my error message

var alertMsg = "Please complete these fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);

return false;
}
}




var count=0;

function validate(frm)
{

//call function for validating, if ny field is empty
formCheck(frm);
//number of days for which the cookie is valid, here it is set to 99 days, may be changed by changin the value
var days=99;
var obj=frm.elements["eMail Address"];
var expires = new Date ();
expires.setTime(expires.getTime() + days * (24 * 60 * 60 * 1000));

if(obj.value==readCookie())
{
alert("Submission not allowed, the person has already filled form previously.The e-mail id is same!!");
count=0;

}
else
{
SetCookie(obj.value,expires);
//alert(readCookie());
count++;

}



}
function eraseCookie(name)
{
SetCookie( "", -1);
}

//function for reading cookie
function readCookie()
{
var ca = document.cookie.split(';');
var nameEQ = "TotalSubmissions" + "=";
for(var i=0; i < ca.length; i++)
{
var c = ca[i];
while (c.charAt(0)==' ')
c = c.substring(1, c.length);
//delete spaces
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}



//setting up cookie

function SetCookie(cookieData, expireDate)
{
document.cookie = "TotalSubmissions" + "=" + escape(cookieData) + "; expires=" + expireDate.toGMTString();
}

function GetCookie(name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}





function redirect()
{
if(!count)
location.href = 'Confirm.html';
else
location.href = 'Error.html';


}


//-->
</SCRIPT>


</head>

<body>


<body bgcolor="#000110"></body>



<center><table width="850" bgcolor="#c69b96"></center>

<tr>
<td>

<H1>Kudler Mailing list</H1><!-- Header #1 -->
<H3>In order to recieve online coupons please fill out the form below.</H3>

<hr size="10" width="100%" noshade>

<form name="Customer" onsubmit="return formCheck(this);" form action="javascript:redirect();"><!-- Form action -->

First Name:<br> <INPUT size=35 name=FirstName><br>
Last Name:<br> <INPUT size=35 name=LastName><br>
Address:<br> <INPUT size=35 name=Address><br>
City:<br> <INPUT size=35 name=City><br>
State: <br>
<select name="States">
<option value="" SELECTED></option><!-- You select the state you reside in -->
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select><br>

Zip: <br><INPUT size=35 name=Zip><br>
Home Phone: <br><INPUT size=35 name="HomePhone"><br>
eMail Address: <br><INPUT size=35 name="eMail Address"><br>

<hr size="10" width="100%" noshade>

<INPUT type=submit value="Submit Form"> <!-- The two buttons at bottom of page -->
<INPUT type=reset value="Clear Fields" name=clear><br><br>


</td>
</tr>
</table>

</body>
</html>

nacummings is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may 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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java script help Network67 Applications and Operating Systems 0 March 25th, 2005 04:48 AM
Java Script - Help! rcwabbits Webmastering and Programming 0 April 24th, 2003 11:44 PM
Java script and IE Bill in SD, CA Applications and Operating Systems 2 April 10th, 2003 03:39 PM
java script links Emc2 Webmastering and Programming 2 January 10th, 2003 07:20 PM
Daveleau, you need a life vest? desmocat IMO Community 1 July 2nd, 2002 11:13 PM

Most Active Discussions
Is It Just Me? (530)
Misery Loves Company... (1849)
Why Does the MOON Grow Bigger as It.. (18)
heatsink issue (10)
New Mobo (18)
UPGRADING C/D DRIVE TO 250GB & .. (14)
1 internet. 1 house. 3 computer. ho.. (13)
SSD's, RAID, and External Backup (7)
Is This A Compatible Gaming PC? (18)
Recent Discussions
32 or 64 bit vista (4)
Big problem with my PC (2)
system restore 'next' button wo.. (2)
Building my first PC and need s.. (1)
firewall (1)
C++ compiler suggestions (4)
Official World of Warcraft Thre.. (4529)
Programming question (2)
UPGRADING C/D DRIVE TO 250GB &a.. (14)
FS: Dell 6000 laptop, modded 36.. (2)
Apple iPod touch 16 GB $200 (4)
Six 28-Disc Cross Design Black .. (4)


All times are GMT -4. The time now is 12:19 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28