Help needed with Check box form validation

Stuck on getting checkboxes in form to validate

Page 1 of 1

12 Replies - 1088 Views - Last Post: 30 October 2008 - 05:46 PM

#1 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Help needed with Check box form validation

Post icon  Posted 30 October 2008 - 07:00 AM

I am having problems with my form validation, it wants to skip the first item to be checked,
I tried several things but admittedly am not sure what they do, only that they didn't work.

								<input type="checkbox" name="Location[1]" value="News-Leader.com">News-Leader (News-Leader.com)</input><br>

								<input type="checkbox"  name="Location[2]" value="MomsLikeMe.com">Ozarks Moms (MomsLikeMe.com)</input><br>
								
								<input type="checkbox"  name="Location[3]" value="OzarksSpaces.com">Spaces (OzarksSpaces.com)</input><br>
								<input type="checkbox" name="Location[4]" value="OzarksSignature.com">Signature (OzarksSignature.com)</input><br>
								<input type="checkbox" name="Location[5]" value="BaxterBulletin.com">The Baxter Bulletin (BaxterBulletin.com)</input><br>
								<input type="checkbox"  name="Location[6]" value="MyGuideon.com">The Guideon (MyGuideon.com)</input><br>


Then at the bottom the java script:

<script language="Javascript" type="text/javascript">
function validForm(workorderNew) {
if (workorderNew.Location.value == "") { 
alert("You must enter a Location");
workorderNew.Location.focus();
workorderNew.Location.select();
return false;
}


Well I have been scanning the forums and tried this but it doesn't work either, it just automatically sends the form without checking the form fields.
#
// Get the checkbox array length and iterate it to see if any of them is selected
#
		for (var i = 0; i < chks.length; i++)
#
		{
#
				if (chks[i].checked)
#
				{
#
						hasChecked = true;
#
						break;
#
				}
#
		}
#
		// if ishasChecked is false then throw the error message
#
		if (!hasChecked)
#
		{
#
				alert("Please select at least one language.");
#
				chks[0].focus();
#
				return false;
#
		}


The HTML still looks like:
								<input type="checkbox" name="Location[]" id="location1" value="News-Leader.com">News-Leader (News-Leader.com)</input><br>

Really need some help I'm stuck....
Thanks in Advance for points in the right direction

This post has been edited by Terion: 30 October 2008 - 08:43 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help needed with Check box form validation

#2 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Help needed with Check box form validation

Posted 30 October 2008 - 10:57 AM

There are a couple problems but to get you started in the right direction consider the following. You checkbox names are "Location[x]" which means you will need to directly call each checkbox by its name like getElementById('Location[x]'). What I think you are trying to accomplish is to name all the checkboxes the same <....name="Location"....> Then in your code you can access them like this
var chk0 = workorderNew.Location[0];
var chk1 = workorderNew.Location[1];
//etc.


Was This Post Helpful? 0
  • +
  • -

#3 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 11:24 AM

View Postxerxes333, on 30 Oct, 2008 - 10:57 AM, said:

There are a couple problems but to get you started in the right direction consider the following. You checkbox names are "Location[x]" which means you will need to directly call each checkbox by its name like getElementById('Location[x]'). What I think you are trying to accomplish is to name all the checkboxes the same <....name="Location"....> Then in your code you can access them like this
var chk0 = workorderNew.Location[0];
var chk1 = workorderNew.Location[1];
//etc.




Could it work if I add 'id' to the check box fields, the Location name is also the field name for the db, so I would need to say

var Location = location1, location2 etc ?

Oi...
Was This Post Helpful? 0
  • +
  • -

#4 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Help needed with Check box form validation

Posted 30 October 2008 - 11:44 AM

No the id attribute needs to be unique. If you cannot control the name of the input element ten I would suggest something like this.

var inputs = workorderNew.getElementsByTagName('input');

//loop through all the input elements in the form
for(i=0;i<inputs.length;i++){
	//if the current element is a checkbox grab it
	if(inputs[i].getAttribute('type') == 'checkbox'){
		var chk = inputs[i];
		//do stuff with the checkbox
		//blah 
		//blah 
		//blah 
	}
}

Was This Post Helpful? 0
  • +
  • -

#5 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 12:22 PM

Well I am trying a new way and stuck again, I'm really learning today to dislike javascript
Anyways can someone Please help me figure this out, I thought maybe it would be easier to use the getElementById. but I'm all messed up with the phrasing at this point

<script language="Javascript">
function validForm()
{
   var ckLoc1, ckLoc2, ckLoc3, ckLoc4, ckLoc5, fWorkOrderName, fAccountNum, fAdvertiser, fAddress, fCity, fState, fZip, fPhone, fClickThru, fAdSize, fStartMonth, fStartDay, fStartYear, fEndMonth, fEndDay, fEndYear, fPackage, fSalesperson, fSalespersonID, fSalespersonExt, fNameCampaign, fPrintMonth, fPrintDay, fPrintYear, fElectronicAd, fArtInstructions, fBsz1, fBsz2, fBsz3, fBsz4, fBsz5, fBsz6, fBType1, fBType2, fBType3, fBType4;
   with(window.document.workorderNew)
   {
	  ckLoc1   = Location[1];
	  ckLoc2   = Location[2];
	  ckLoc3   = Location[3];
	  ckLoc4   = Location[4];
	  ckLoc5   = Location[5];
	  fWorkOrderName = WorkOrderName;
	  fAccountNum = AccountNum; 
	  fAdvertiser = Advertiser;
	  fAddress = Address; 
	  fCity = City;
	  fState = State;
	  fZip = Zip; 
	  fPhone = Phone;
	  fClickThru = ClickThru;
	  fAdSize = AdSize;
	  fStartMonth = StartMonth;
	  fStartDay = StartDay;
	  fStartYear = StartYear;
	  fEndMonth = EndMonth;
	  fEndDay = EndDay;
	  fEndYear = EndYear; 
	  fPackage = Package;
	  fArtInstructions = ArtInstructions;
	  fBsz1 = BannerSize[1];
	  fBsz2 = BannerSize[2];
	  fBsz3 = BannerSize[3];
	  fBsz4 = BannerSize[4];
	  fBsz5 = BannerSize[5];
	  fBsz6 = BannerSize[6];
	  fBType1 = BannerType[1];
	  fBType2 = BannerType[2];
	  fBType3 = BannerType[3];
	  fBType4 = BannerType[4];
   }

   if(getElementById(ckLoc1.value) == '')
   {

then would I else/if thru the rest of the check boxes, I thought but it just submits the form
Was This Post Helpful? 0
  • +
  • -

#6 JMRKER  Icon User is online

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 12:44 PM

First, you need to change this:
if(getElementById(ckLoc1.value) == '')
{
to
if(getElementById(ckLoc1).value == '')
{

If that still doesn't work, I would remove the "with" statement and call the object directly. I have found out in the past that what I think I'm working "with" is not the same as what the computer thinks it is operating "with". To assure youself of the proper check, I would scatter a few alerts("message") about to see what the values are where you expect them to be.
Was This Post Helpful? 0
  • +
  • -

#7 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Help needed with Check box form validation

Posted 30 October 2008 - 12:47 PM

OK aside from doing the code for you try this. This stays with the original way you were trying to validate the form.

<html>
<script type="text/javascript">
var VALID = false;

function validateForm(){
	var inputs = workorderNew.getElementsByTagName('input');
	for(i=0;i<inputs.length;i++){
		//if the current element is a checkbox grab it
		if(inputs[i].type == 'checkbox'){
			var chk = inputs[i];
			//if any checkbox is CHECKED then the form is valid
			if(chk.checked)
				VALID = true;
		}
	}
	alert(VALID);
}
</script>

<form name="workorderNew">
	<input type="checkbox" name="Location[1]" value="News-Leader.com">News-Leader (News-Leader.com)</input><br>
	<input type="checkbox"  name="Location[2]" value="MomsLikeMe.com">Ozarks Moms (MomsLikeMe.com)</input><br>
	<button onclick="validateForm()">Button</button>
</form>
</html>

Was This Post Helpful? 0
  • +
  • -

#8 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 01:09 PM

Well try number 4million....sigh

Here is how I'm trying now
function validForm(workorderNew) {
var loc1 = document.this(workorderNew.Location('Location[1]'));
var loc2 = document.this(workorderNew.Location('Location[2]'));
var loc3 = document.this(workorderNew.Location('Location[3]'));
var loc4 = document.this(workorderNew.Location('Location[4]'));
var loc5 = document.this(workorderNew.Location('Location[5]'));
var loc6 = document.this(workorderNew.Location('Location[6]'));
	
if (workorderNew.loc1.value == "") { 
alert("You must enter a Location");
workorderNew.Location.focus();
workorderNew.Location.select();
return false;
}
else if (workorderNew.loc2.value == "") { 
alert("You must enter a Location");
workorderNew.Location.focus();
workorderNew.Location.select();
return false;
}


can someone explain why this doesn't work
even if no checkbox is checked it submits the form, and does not continue down the validation
should i be using just if's....

This post has been edited by Terion: 30 October 2008 - 01:13 PM

Was This Post Helpful? 0
  • +
  • -

#9 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Help needed with Check box form validation

Posted 30 October 2008 - 01:34 PM

try posting all the code (clean it up first) because I'm sure you function is working fine but I suspect the method that you are using to submit the form is whats screwing things up. Also if you notice the code I posted previously, it works just fine. Cut/paste it into a new file and try it yourself if you don't believe me.
Was This Post Helpful? 0
  • +
  • -

#10 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 01:37 PM

View Postxerxes333, on 30 Oct, 2008 - 12:47 PM, said:

OK aside from doing the code for you try this. This stays with the original way you were trying to validate the form.

<html>
<script type="text/javascript">
var VALID = false;

function validateForm(){
	var inputs = workorderNew.getElementsByTagName('input');
	for(i=0;i<inputs.length;i++){
		//if the current element is a checkbox grab it
		if(inputs[i].type == 'checkbox'){
			var chk = inputs[i];
			//if any checkbox is CHECKED then the form is valid
			if(chk.checked)
				VALID = true;
		}
	}
	alert(VALID);
}
</script>

<form name="workorderNew">
	<input type="checkbox" name="Location[1]" value="siteurl.com">News-Leader (News-Leader.com)</input><br>
	<input type="checkbox"  name="Location[2]" value="anothersiteurl.com">Ozarks Moms (MomsLikeMe.com)</input><br>
	<button onclick="validateForm()">Button</button>
</form>
</html>

Thanks this would be so helpful, except I have only been posting my problem spot in the form the form itself is huge over 1000 lines of code, I could post the whole thing, should I?
Was This Post Helpful? 0
  • +
  • -

#11 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 01:58 PM

Moving right along found something that looks like it should work, but it doesn't
I agree the form field 'location' all being the same name for the checkboxes is the problem
right...
But look at this it should work some how but I think I have to use getElementById because I can give the checkboxes their own id's
if (document.workorderNew.loc1.checked == false &&
document.workorderNew.loc2.checked == false &&
document.workorderNew.loc3.checked == false && 
document.workorderNew.loc4.checked == false && 
document.workorderNew.loc5.checked == false &&
document.workorderNew.loc6.checked == false ) { 
alert("You must check a Location box");
workorderNew.Location.focus();
workorderNew.Location.select();
return false;
}


Was This Post Helpful? 0
  • +
  • -

#12 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: Help needed with Check box form validation

Posted 30 October 2008 - 02:15 PM

Now I just tried this and nada nothing is working
<script language="Javascript" type="text/javascript">
function validForm(workorderNew) {
var locChk1 = document.GetElementById('loc1');
var locChk2 = document.GetElementById('loc2');
var locChk3 = document.GetElementById('loc3');
var locChk4 = document.GetElementById('loc4');
var locChk5 = document.GetElementById('loc5');
var locChk6 = document.GetEkementById('loc6');
	
if (document.workorderNew.locChk1.checked == false &&
document.workorderNew.locChk2.checked == false &&
document.workorderNew.locChk3.checked == false && 
document.workorderNew.locChk4.checked == false && 
document.workorderNew.locChk5.checked == false &&
document.workorderNew.locChk6.checked == false ) { 
alert("You must check a Location box");
workorderNew.Location.focus();
workorderNew.Location.select();
return false;
}


Xerxes I believe you that it works I just didn't know how to incorporate into a form that has many many fields to validate its a huge form...
Here goes:
[code]<?php
include("inc/dbconn_open.php");

if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){
header ("Location: LogOut.php");
}

if (isset($_POST['AdminID'])){
$AdminID = $_POST['AdminID'];
} elseif (isset($_GET['AdminID'])){
$AdminID = $_GET['AdminID'];
} else {
header ("Location: LogOut.php");
}

if (isset($_POST['GO'])){$GO = $_POST['GO'];} else {$GO = "";}
if (isset($_POST['Location'])){$Location = $_POST['Location'];} else {$Location = "";}
{$errmsg = 'Please Select a Location';}
if (isset($_POST['WorkOrderName'])){$WorkOrderName = $_POST['WorkOrderName'];} else {$WorkOrderName = "";}
if (isset($_POST['IONumber'])){$IONumber = $_POST['IONumber'];} else {$IONumber = "";}
if (isset($_POST['OrderType'])){$OrderType = implode($_POST['OrderType'],',');} else {$OrderType = "";}
if (isset($_POST['WorkOrderNumber'])){$WorkOrderNumber = $_POST['WorkOrderNumber'];} else {$WorkOrderNumber = "";}
if (isset($_POST['Advertiser'])){$Advertiser = $_POST['Advertiser'];} else {$Advertiser = "";}
if (isset($_POST['AccountNum'])){$AccountNum = $_POST['AccountNum'];} else {$AccountNum = "";}
if (isset($_POST['Address'])){$Address = $_POST['Address'];} else {$Address = "";}
if (isset($_POST['City'])){$City = $_POST['City'];} else {$City = "";}
if (isset($_POST['State'])){$State = $_POST['State'];} else {$State = "";}
if (isset($_POST['Zip'])){$Zip = $_POST['Zip'];} else {$Zip = "";}
if (isset($_POST['Phone'])){$Phone = $_POST['Phone'];} else {$Phone = "";}
if (isset($_POST['Fax'])){$Fax = $_POST['Fax'];} else {$Fax = "";}
if (isset($_POST['ContactName'])){$ContactName = $_POST['ContactName'];} else {$ContactName = "";}
if (isset($_POST['URL'])){$URL = $_POST['URL'];} else {$URL = "";}
if (isset($_POST['AdvertisingAgency'])){$AdvertisingAgency = $_POST['AdvertisingAgency'];} else {$AdvertisingAgency = "";}
if (isset($_POST['ClickThru'])){$ClickThru = $_POST['ClickThru'];} else {$ClickThru = "";}
if (isset($_POST['Impressions'])){$Impressions = $_POST['Impressions'];} else {$Impressions = "";}
if (isset($_POST['AdSize'])){$AdSize = $_POST['AdSize'];} else {$AdSize = "";}
if (isset($_POST['StartMonth']) && isset($_POST['StartDay']) && isset($_POST['StartYear'])){
$StartDate = $_POST['StartYear'] ."-". $_POST['StartMonth'] ."-". $_POST['StartDay'];
} else {
$StartDate = "";
}
if (isset($_POST['EndMonth']) && isset($_POST['EndDay']) && isset($_POST['EndYear'])){
$EndDate = $_POST['EndYear'] ."-". $_POST['EndMonth'] ."-". $_POST['EndDay'];
} else {
$EndDate = "";
}
if (isset($_POST['CPM'])){$CPM = $_POST['CPM'];} else {$CPM = "";}
if (isset($_POST['FlatRate'])){$FlatRate = $_POST['FlatRate'];} else {$FlatRate = "";}
if (isset($_POST['IncludeSites'])){$IncludeSites = $_POST['IncludeSites'];} else {$IncludeSites = "";}
if (isset($_POST['Package'])){$Package = $_POST['Package'];} else {$Package = "";}

if (isset($_POST['Salesperson'])){$Salesperson = $_POST['Salesperson'];} else {$Salesperson = "";}
if (isset($_POST['SalespersonID'])){$SalespersonID = $_POST['SalespersonID'];} else {$SalespersonID = "";}
if (isset($_POST['SalespersonEmail'])){$SalespersonEmail = $_POST['SalespersonEmail'];} else {$SalespersonEmail = "";}
if (isset($_POST['SalespersonExt'])){$SalespersonExt = $_POST['SalespersonExt'];} else {$SalespersonExt = "";}
if (isset($_POST['NameCampaign'])){$NameCampaign = $_POST['NameCampaign'];} else {$NameCampaign = "";}
if (isset($_POST['SpecialInstructions'])){$SpecialInstructions = $_POST['SpecialInstructions'];} else {$SpecialInstructions = "";}
if (isset($_POST['AdContactName'])){$AdContactName = $_POST['AdContactName'];} else {$AdContactName = "";}
if (isset($_POST['AdContactPhone'])){$AdContactPhone = $_POST['AdContactPhone'];} else {$AdContactPhone = "";}
if (isset($_POST['AdContactEmail'])){$AdContactEmail = $_POST['AdContactEmail'];} else {$AdContactEmail = "";}
if (isset($_POST['Artwork'])){$Artwork = $_POST['Artwork'];} else {$Artwork = "";}
if (isset($_POST['PrintMonth']) && isset($_POST['PrintDay']) && isset($_POST['PrintYear'])){
$PrintDate = $_POST['PrintYear'] ."-". $_POST['PrintMonth'] ."-". $_POST['PrintDay'];
} else {
$PrintDate = "";
}
if (isset($_POST['ElectronicAd'])){$ElectronicAd = $_POST['ElectronicAd'];} else {$ElectronicAd = "";}
if (isset($_POST['EmailProof'])){$EmailProof = $_POST['EmailProof'];} else {$EmailProof = "";}
if (isset($_POST['ProofMonth']) && isset($_POST['ProofDay']) && isset($_POST['ProofYear'])){
$ProofDate = $_POST['ProofYear'] ."-". $_POST['ProofMonth'] ."-". $_POST['ProofDay'];
} else {
$ProofDate = "";
}
if (isset($_POST['ArtInstructions'])){$ArtInstructions = $_POST['ArtInstructions'];} else {$ArtInstructions = "";}
if (isset($_POST['Focus'])){$Focus = $_POST['Focus'];} else {$Focus = "";}
if (isset($_POST['BannerSize'])){$BannerSize = implode($_POST['BannerSize'],',');} else {$BannerSize = "";}
if (isset($_POST['BannerSizeOther'])){$BannerSizeOther = $_POST['BannerSizeOther'];} else {$BannerSizeOther = "";}
if (isset($_POST['BannerType'])){$BannerType = implode($_POST['BannerType'],',');} else {$BannerType = "";}
if (isset($_POST['BannerTypeOther'])){$BannerTypeOther = $_POST['BannerTypeOther'];} else {$BannerTypeOther = "";}
if (isset($_POST['ExtraImage1Desc'])){$ExtraImage1Desc = $_POST['ExtraImage1Desc'];} else {$ExtraImage1Desc = "";}
if (isset($_POST['ExtraImage2Desc'])){$ExtraImage2Desc = $_POST['ExtraImage2Desc'];} else {$ExtraImage2Desc = "";}
if (isset($_POST['ExtraImage3Desc'])){$ExtraImage3Desc = $_POST['ExtraImage3Desc'];} else {$ExtraImage3Desc = "";}
if (isset($_POST['ExtraImage4Desc'])){$ExtraImage4Desc = $_POST['ExtraImage4Desc'];} else {$ExtraImage4Desc = "";}
if (isset($_POST['ExtraImage5Desc'])){$ExtraImage5Desc = $_POST['ExtraImage5Desc'];} else {$ExtraImage5Desc = "";}

if ($GO == "Save") {
$sql = "SELECT Name FROM admin WHERE AdminID='$AdminID'";
$result = mysql_query ($sql);
$row = mysql_fetch_object ($result);

$Notes = "~". date("F j, Y g:i a") ." - Work Order Submitted by ". $row->Name ."\n";

$sql = "INSERT INTO workorders (CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes) VALUES (";
$sql .= "Now(), '$Location', '$WorkOrderName', '$AdminID', 'WorkOrder', 'New Order', '$Notes')";
mysql_query($sql);
$WorkOrderID = mysql_insert_id();


if ($_FILES) {
if (isset($_FILES['ExtraImage1'])) {
if (is_uploaded_file ($_FILES['ExtraImage1']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage1']['name'])));
$ExtraImage1Name = "Artwork/". $WorkOrderID ."_Image1.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage1']['tmp_name'],$ExtraImage1Name);
}
}
if (isset($_FILES['ExtraImage2'])) {
if (is_uploaded_file ($_FILES['ExtraImage2']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage2']['name'])));
$ExtraImage2Name = "Artwork/". $WorkOrderID ."_Image2.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage2']['tmp_name'],$ExtraImage2Name);
}
}
if (isset($_FILES['ExtraImage3'])) {
if (is_uploaded_file ($_FILES['ExtraImage3']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage3']['name'])));
$ExtraImage3Name = "Artwork/". $WorkOrderID ."_Image3.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage3']['tmp_name'],$ExtraImage3Name);
}
}
if (isset($_FILES['ExtraImage4'])) {
if (is_uploaded_file ($_FILES['ExtraImage4']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage4']['name'])));
$ExtraImage4Name = "Artwork/". $WorkOrderID ."_Image4.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage4']['tmp_name'],$ExtraImage4Name);
}
}
if (isset($_FILES['ExtraImage5'])) {
if (is_uploaded_file ($_FILES['ExtraImage5']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage5']['name'])));
$ExtraImage5Name = "Artwork/". $WorkOrderID ."_Image5.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage5']['tmp_name'],$ExtraImage5Name);
}
}
}


$sql = "INSERT INTO workorderform (WorkOrderID, CreatedDate, IONumber, OrderType, WorkOrderNumber, Advertiser, AccountNum, ";
$sql .= "Address, City, State, Zip, Phone, Fax, ContactName, URL, AdvertisingAgency, ClickThru, Impressions, AdSize, ";
$sql .= "StartDate, EndDate, CPM, FlatRate, IncludeSites, Package, Matrix, MatrixDate, Salesperson, SalespersonID, ";
$sql .= "SalespersonEmail, SalespersonExt, NameCampaign, SpecialInstructions, AdContactName, AdContactPhone, AdContactEmail, ";
$sql .= "Artwork, PrintDate, ElectronicAd, EmailProof, ProofDate, ArtInstructions, Focus, BannerSize, BannerSizeOther, ";
$sql .= "BannerType, BannerTypeOther, ExtraImage1, ExtraImage1Desc, ExtraImage2, ExtraImage2Desc, ExtraImage3, ";
$sql .= "ExtraImage3Desc, ExtraImage4, ExtraImage4Desc, ExtraImage5, ExtraImage5Desc) VALUES (";
$sql .= "'". mysql_real_escape_string($WorkOrderID) ."', ";
$sql .= "Now(), ";
$sql .= "'". mysql_real_escape_string($IONumber) ."', ";
$sql .= "'". mysql_real_escape_string($OrderType) ."', ";
$sql .= "'". mysql_real_escape_string($WorkOrderNumber) ."', ";
$sql .= "'". mysql_real_escape_string($Advertiser) ."', ";
$sql .= "'". mysql_real_escape_string($AccountNum) ."', ";
$sql .= "'". mysql_real_escape_string($Address) ."', ";
$sql .= "'". mysql_real_escape_string($City) ."', ";
$sql .= "'". mysql_real_escape_string($State) ."', ";
$sql .= "'". mysql_real_escape_string($Zip) ."', ";
$sql .= "'". mysql_real_escape_string($Phone) ."', ";
$sql .= "'". mysql_real_escape_string($Fax) ."', ";
$sql .= "'". mysql_real_escape_string($ContactName) ."', ";
$sql .= "'". mysql_real_escape_string($URL) ."', ";
$sql .= "'". mysql_real_escape_string($AdvertisingAgency) ."', ";
$sql .= "'". mysql_real_escape_string($ClickThru) ."', ";
$sql .= "'". mysql_real_escape_string($Impressions) ."', ";
$sql .= "'". mysql_real_escape_string($AdSize) ."', ";
$sql .= "'". mysql_real_escape_string($StartDate) ."', ";
$sql .= "'". mysql_real_escape_string($EndDate) ."', ";
$sql .= "'". mysql_real_escape_string($CPM) ."', ";
$sql .= "'". mysql_real_escape_string($FlatRate) ."', ";
$sql .= "'". mysql_real_escape_string($IncludeSites) ."', ";
$sql .= "'". mysql_real_escape_string($Package) ."', ";
$sql .= "'". mysql_real_escape_string($Matrix) ."', ";
$sql .= "'". mysql_real_escape_string($MatrixDate) ."', ";
$sql .= "'". mysql_real_escape_string($Salesperson) ."', ";
$sql .= "'". mysql_real_escape_string($SalespersonID) ."', ";
$sql .= "'". mysql_real_escape_string($SalespersonEmail) ."', ";
$sql .= "'". mysql_real_escape_string($SalespersonExt) ."', ";
$sql .= "'". mysql_real_escape_string($NameCampaign) ."', ";
$sql .= "'". mysql_real_escape_string($SpecialInstructions) ."', ";
$sql .= "'". mysql_real_escape_string($AdContactName) ."', ";
$sql .= "'". mysql_real_escape_string($AdContactPhone) ."', ";
$sql .= "'". mysql_real_escape_string($AdContactEmail) ."', ";
$sql .= "'". mysql_real_escape_string($Artwork) ."', ";
$sql .= "'". mysql_real_escape_string($PrintDate) ."', ";
$sql .= "'". mysql_real_escape_string($ElectronicAd) ."', ";
$sql .= "'". mysql_real_escape_string($EmailProof) ."', ";
$sql .= "'". mysql_real_escape_string($ProofDate) ."', ";
$sql .= "'". mysql_real_escape_string($ArtInstructions) ."', ";
$sql .= "'". mysql_real_escape_string($Focus) ."', ";
$sql .= "'". mysql_real_escape_string($BannerSize) ."', ";
$sql .= "'". mysql_real_escape_string($BannerSizeOther) ."', ";
$sql .= "'". mysql_real_escape_string($BannerType) ."', ";
$sql .= "'". mysql_real_escape_string($BannerTypeOther) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage1Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage1Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage2Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage2Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage3Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage3Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage4Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage4Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage5Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage5Desc) ."')";
mysql_query($sql);

$Message = "<HTML>";
$Message.= "<STYLE TYPE=\"text/css\">";
$Message.= "<!--";
$Message.= "body {font-size:12px; font-family:arial, sans-serif;}";
$Message.= "-->";
$Message.= "</STYLE>";
$Message.= "</HEAD>";
$Message.= "<body>";
$Message.= "A new online work order form was submitted.";
$Message.= "</body>";
$Message = wordwrap($Message, 70);

$Subject = "New Online Work Order Form";
$Email = "amckee@news-leader.com";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: amckee@news-leader.com\r\n";
$headers .= "From: online@news-leader.com\r\n";

@mail($Email, $Subject, $Message, $headers);

?>
<script language="javascript">
alert("Your Online Work Order has been received. \n\nThank You.");
window.location="Welcome.php?AdminID=<?php echo $AdminID; ?>";
</script>
<?php
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Online Work Order Form</title>
<LINK REL="STYLESHEET" HREF="inc/style.css">

<script type=text/javascript>
<!--
var DHTML = (document.getElementById || document.all || document.layers);
function getObj(name){
if (document.getElementById){
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
} else if (document.all) {
this.obj = document.all[name];
this.style = document.all[name].style;
} else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}

function change(name) {
var x = new getObj(name);
if (x.style.visibility == 'visible') {
x.style.visibility = 'hidden';
x.style.display = 'none';
} else {
x.style.visibility = 'visible';
x.style.display = '';
}
}

function Show(name){
var x = new getObj(name);x.style.visibility = 'visible'
var x = new getObj(name);x.style.display = ''
}


function Hide(name){
var x = new getObj(name);x.style.visibility = 'hidden'
var x = new getObj(name);x.style.display = 'none'
}

function status(name) {
var x = new getObj(name);
if (x.style.visibility == 'visible') {
return true;
} else {
return false;
}
}

function ArtworkChange(tmp) {
if (tmp == "YES") {
Show('AdInfo');
Show('AdDim');
Show('AdType');
} else {
Hide('AdInfo');
Hide('AdDim');
Hide('AdType');
}
}
</script>

</head>

<body>
<form name="workorderNew" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validForm(this)" method="post" enctype="multipart/form-data">
<input type="hidden" name="GO" value="Save">
<input type="hidden" name="AdminID" value="<?php echo $AdminID; ?>">
<table width="800" border="0">
<tr>
<td valign="top" colspan="2">
<div class="PageTitle">Online Work Order &amp; Art Request Form</div>
<div class="Requirement">Fields marked with * REQUIRED</div>
</td>
</tr>
<tr>
<td valign="top">
<fieldset>
<legend>Order Information</legend>
<table width="390">
<tr>
<td align="left" nowrap><div class="CaptionReq"><b>*</b>Location:</div></td>
<td align="left">

<input type="checkbox" name="Location" id="loc1" value="News-Leader.com">News-Leader (News-Leader.com)</input><br>

<input type="checkbox" name="Location" id="loc2" value="MomsLikeMe.com">Ozarks Moms (MomsLikeMe.com)</input><br>

<input type="checkbox" name="Location" id="loc3" value="OzarksSpaces.com">Spaces (OzarksSpaces.com)</input><br>
<input type="checkbox" name="Location" id="loc4" value="OzarksSignature.com">Signature (OzarksSignature.com)</input><br>
<input type="checkbox" name="Location" id="loc5" value="BaxterBulletin.com">The Baxter Bulletin (BaxterBulletin.com)</input><br>
<input type="checkbox" name="Location" id="loc6" value="MyGuideon.com">The Guideon (MyGuideon.com)</input><br>

</td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq"><b>*</b>Work Order Name:</div></td>
<td align="left"><input name="WorkOrderName" type="text" size="35" ></td>
</tr>
</table>
</fieldset>
<div>&nbsp;</div>
<fieldset>
<legend>IO/AD Number</legend>
<table width="390">
<tr>
<td align="left" nowrap><div class="Caption">IO/AD Number:</div></td>
<td align="left"><input type="text" name="IONumber" size="35" /></td>
</tr>
</table>
</fieldset>
</td>
<td valign="top">
<fieldset>
<legend>Order Information</legend>
<b>*</b>You MUST choose one option:
<table width="390">
<tr>
<td align="left" nowrap><div class="CaptionReq">Pick Up Order:</div></td>
<td align="left"><input type="checkbox" name="OrderType[]" value="Pick Up Order"></td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq">New Order:</div></td>
<td align="left"><input type="checkbox" name="OrderType[]" value="New Order"></td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq">Change Order:</div></td>
<td align="left" nowrap><input type="checkbox" name="OrderType[]" value="Change Order"></td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq">Spec Ad:</div></td>
<td align="left" nowrap><input type="checkbox" name="OrderType[]" value="Spec Ad"></td>
</tr>
<tr>
<td align="left"><div class="CaptionReq">Work Order #:</div></td>
<td align="left"><input type="text" name="WorkOrderNumber" size="35" /></td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr>
<td valign="top">
<fieldset>
<legend>Account Information</legend>
<table width="390">

<tr>
<td align="left" nowrap><div class="CaptionReq">Account Number:</div></td>
<td align="left"><input type="text" name="AccountNum" size="35" /></td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq"><b>*</b>Advertiser:</div></td>
<td align="left"><input type="text" name="Advertiser" size="35" /></td>
</tr>
<tr>
<td align="left" colspan="2">If You Do not have an Account# You must fill in Address and Phone</td>
</tr>

<tr>
<td align="left" nowrap><div class="CaptionReq"><b>*</b>Address:</div></td>
<td align="left"><input type="text" name="Address" size="35" /></td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq"><b>*</b>City:</div></td>
<td align="left"><input type="text" name="City" size="35" /></td>
</tr>
<tr>
<td align="left" nowrap><div class="CaptionReq"><b>*</b>State:</div></td>
<td align="left">
<select name="State" style="width:180">
<option value="">Select...</option>

<option value="">------US States------</option>
<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" selected>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>
 &nbs
Was This Post Helpful? 0
  • +
  • -

#13 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Help needed with Check box form validation

Posted 30 October 2008 - 05:46 PM

This will do what you are looking for (obviously simplified)
<html>
<script type="text/javascript">
var VALID = false;

function validateForm(){
	var inputs = workorderNew.getElementsByTagName('input');
	for(i=0;i<inputs.length;i++){
		//if the current element is a checkbox grab it
		if(inputs[i].type == 'checkbox'){
			var chk = inputs[i];
			//if any checkbox is CHECKED then the form is valid
			if(chk.checked)
				VALID = true;
		}
	}
	if(!VALID) alert(VALID);
	return VALID;
}
</script>

<form name="workorderNew" onsubmit="return validateForm()" method="get">
	<input type="checkbox" name="Location[1]" value="News-Leader.com">News-Leader (News-Leader.com)</input><br>
	<input type="checkbox"  name="Location[2]" value="MomsLikeMe.com">Ozarks Moms (MomsLikeMe.com)</input><br>
	<input type="submit" value="Submit">
</form>
</html> 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1