how to assign check box items to an array (Full Version)

All Forums >> [Web Development] >> Microsoft FrontPage Help



Message


laticca8 -> how to assign check box items to an array (8/22/2005 4:26:57)

hello, all. i have a form in which i want to verify that at least one of the checkboxes have been checked. how do i assign the checkboxes to an array?

here is a select part of the form (though there are several more options):

<BLOCKQUOTE>
<P>
<font face="Tahoma"><span style="font-size: 9pt">
<INPUT TYPE=CHECKBOX NAME="bizstartup" value="0">
Startup Services<BR>
<INPUT TYPE=CHECKBOX NAME="bizcredit" value="0">
Credit Services<BR>
<INPUT TYPE=CHECKBOX NAME="taxrecovery" value="0">
Tax Recovery<BR>
<INPUT TYPE=CHECKBOX NAME="strategicplan" value="0">
Strategic Plan Consulting<BR>
<INPUT TYPE=CHECKBOX NAME="processimprovemt" value="0">
Process Improvement Consulting<BR>
<INPUT TYPE=CHECKBOX NAME="bizaudit" value="0">
Business Audit<BR>
</span></font>
</P>
</BLOCKQUOTE>





Tailslide -> RE: how to assign check box items to an array (8/22/2005 5:24:53)

Hi

This works:

function validateBoxes(theForm){
	var numBoxes= 0;
	for(i=0;i<theForm.services.length; i++){
		if (theForm.services.checked){
			numBoxes++;
		}
	}
	
	if (numBoxes < 1){
		alert("Please select at least one Service");
		return false;
	}
	
	else {
		return true;
	}
}
	


I've had to fiddle with the names/ids/values a bit - the names of all the checkboxes are now "service" and the value is "bizstartup" for example.

Here's a live test: http://www.littleblueplane.com/test/checkboxformtest2.html. Feel free to view source and copy the lot.

Edited: fiddled with it a bit because it was misbehaving in FF - now working fine.




laticca8 -> RE: how to assign check box items to an array (8/22/2005 10:45:03)

thanks a million, tailslide! i'll give it a shot![:D]




laticca8 -> RE: how to assign check box items to an array (8/22/2005 11:03:24)

uh, tailslide! you are the bomb with creating the little test page for me! [sm=bowdown.gif] but, i have one more question. how would i include that in this existing validation script:

function Validatetfsinforequest()
{
var contactmethod = document.tfsinforequest.contactmethod;
var email = document.tfsinforequest.email;
var address = document.tfsinforequest.address;

if (contactmethod.selectedIndex < 1)
{
alert("Please provide your preferred method of contact.");
contactmethod.focus();
return false;
}
if ((contactmethod.selectedIndex==1) && (email.value == ""))
{
window.alert("Please enter your email address.");
email.focus();
return false;
}
if ((contactmethod.selectedIndex==2) && (address.value == ""))
{
window.alert("Please enter your mailing address.");
address.focus();
return false;
}
return true;
}

my form, method, post, action line states:

<form name="tfsinforequest" method="post" action="http://www.tricapacademy.org/tfsinfoconfirm.php"
onSubmit="return Validatetfsinforequest();">




Tailslide -> RE: how to assign check box items to an array (8/22/2005 11:24:16)

Now I'm not betting my life that this'll work [:D] because forms are "interesting" in a "always going wrong" type of way!

Without the rest of your form it's difficult to be sure - but it works for me once I did a little fiddling (can't help myself!).

I have no idea why - but it wouldn't work unless I changed the name slightly (sorry!)- if I understood JS a bit better I might be able to tell you why but I don't...

Anway - have a look at the live version and view source to see what I did: http://www.littleblueplane.com/test/checkboxformtest2.html

In case I ever take that page down I'll paste the sections I changed in below:

function validate(tfsinforequest){
	var numBoxes= 0;
	for(i=0;i<tfsinforequest.services.length; i++){
		if (tfsinforequest.services.checked){
			numBoxes++;
		}
	}
	
	if (numBoxes < 1){
		alert("Please select at least one Service");
		return false;
	}
	
	else {
		return true;
	}
}
	
//]]>
</script>
</head>
<body>

<div id="checkboxes" style="font-family: Tahoma; font-size: 76%;">
<p>Please choose one</p>
 <form name="tfsinforequest" method="post" action="http://www.tricapacademy.org/tfsinfoconfirm.php" onsubmit="return validate(this);">


Hopefully the rest of your validation script could be slipped into the above script!

If you have problems then you'll need to post the whole lot - better chance of fixing it that way!





laticca8 -> RE: how to assign check box items to an array (8/22/2005 11:30:15)

nope, i had tried that. here's the rest of the form. this original validation does work though.

<script language="JavaScript" type="text/javascript">

function Validatetfsinforequest()
{
var contactmethod = document.tfsinforequest.contactmethod;
var email = document.tfsinforequest.email;
var address = document.tfsinforequest.address;

if (contactmethod.selectedIndex < 1)
{
alert("Please provide your preferred method of contact.");
contactmethod.focus();
return false;
}
if ((contactmethod.selectedIndex==1) && (email.value == ""))
{
window.alert("Please enter your email address.");
email.focus();
return false;
}
if ((contactmethod.selectedIndex==2) && (address.value == ""))
{
window.alert("Please enter your mailing address.");
address.focus();
return false;
}
var numBoxes= 0;
for(i=0;i<tfsinforequest.services.length; i++){
if (tfsinforequest.services.checked){
numBoxes++;
}
}

if (numBoxes < 1){
alert("Please select at least one Service");
return false;
}

else {
return true;
}
}

// -->
</script>

<form name="tfsinforequest" method="post" action="http://www.tricapacademy.org/tfsinfoconfirm.php"
onSubmit="return Validatetfsinforequest();">
<input type="hidden" name="id" value="NULL">
<div align="left">
<p class="title01" style="margin-bottom: 8pt"><span style="font-size: 16pt">
Request for More Information</span></p>
<table border="0" id="table1">
<tr>
<td align="right"><b><font face="Tahoma" style="font-size: 9pt">Name</font></b></td>
<td><font face="Tahoma"><span style="font-size: 9pt">
<INPUT NAME="name" SIZE=50></span></font></td>
</tr>
<tr>
<td align="right"><b><font face="Tahoma" style="font-size: 9pt">
Preferred Contact Method</font></b></td>
<td><font face="Tahoma"><span style="font-size: 9pt">
 <SELECT NAME="contactmethod" size="1">
<option selected>Please select one</option>
<OPTION>Email
<OPTION>Postal Delivery
</SELECT></span></font></td>
</tr>
<tr>
<td align="right"><b><font face="Tahoma" style="font-size: 9pt">
Email Address* </font></b></td>
<td><font face="Tahoma"><span style="font-size: 9pt">
<INPUT NAME="email" SIZE=25></span></font></td>
</tr>
<tr>
<td align="right" valign="top"><b>
<font face="Tahoma" style="font-size: 9pt">Postal Address* </font>
</b></td>
<td><font face="Tahoma"><span style="font-size: 9pt">
<TEXTAREA NAME="address" ROWS=5 COLS=35></TEXTAREA></span></font></td>
</tr>
</table>
</div>
<p style="margin-top: 0"><font face="Tahoma" size="1"><b>* These fields are
required only if chosen as the preferred method of contact.</b></font></p>
<BLOCKQUOTE>
</BLOCKQUOTE>
<P>
<font face="Tahoma" style="font-size: 9pt">How did you hear about us?   
</font><font face="Tahoma"><span style="font-size: 9pt">
<SELECT NAME="referral" size="1">
<option selected>Please select one</option>
<OPTION>I am a returning customer.
<OPTION>Referral from a friend/relative/associate
<OPTION>Google.com
<OPTION>Other search engine
<OPTION>I saw/clicked on your link on another site.
<OPTION>Other
</SELECT></span></font></P>
<P>
</P>
<P>
<font style="font-size: 10pt; font-weight: 700" face="Tahoma">I
would like to receive additional information about the following services:</font></P>
<P>
<font face="Tahoma" style="font-size: 9pt">Please select any of the following <u>Business Services</u> that apply:</font></P>
<BLOCKQUOTE>
<P>
<font face="Tahoma"><span style="font-size: 9pt">
<INPUT TYPE=CHECKBOX NAME="bizstartup" value="0">
Startup Services<BR>
<INPUT TYPE=CHECKBOX NAME="bizcredit" value="0">
Credit Services<BR>
<INPUT TYPE=CHECKBOX NAME="taxrecovery" value="0">
Tax Recovery<BR>
<INPUT TYPE=CHECKBOX NAME="strategicplan" value="0">
Strategic Plan Consulting<BR>
<INPUT TYPE=CHECKBOX NAME="processimprovemt" value="0">
Process Improvement Consulting<BR>
<INPUT TYPE=CHECKBOX NAME="bizaudit" value="0">
Business Audit<BR>
</span></font>
</P>
</BLOCKQUOTE>
<P>
<font face="Tahoma" style="font-size: 9pt">Please select any of the following <u>Church Services</u> that apply:</font></P>
<BLOCKQUOTE>
<P>
<font face="Tahoma"><span style="font-size: 9pt">
<INPUT TYPE=CHECKBOX NAME="churchfinancing" value="0">
Charitable Gifting<BR>
<INPUT TYPE=CHECKBOX NAME="_501c3setup" value="0">
501c3 Setup<BR>
</span></font>
</P>
</BLOCKQUOTE>
<P>
<font face="Tahoma" style="font-size: 9pt">Please select any of the following <u>Personal Services</u> that apply:</font></P>
<BLOCKQUOTE>
<P>
<font face="Tahoma"><span style="font-size: 9pt">
<INPUT TYPE=CHECKBOX NAME="lifeins" value="0">
Burial & Life Insurance<BR>
<INPUT TYPE=CHECKBOX NAME="healthins" value="0">
Health Insurance<BR>
<INPUT TYPE=CHECKBOX NAME="_529plan" value="0">
Education Funding<BR>
<INPUT TYPE=CHECKBOX NAME="_401k" value="0">
Retirement Planning<BR>
<INPUT TYPE=CHECKBOX NAME="disabilityins" value="0">
Disability Insurance<BR>
</span></font>
</P>
</BLOCKQUOTE>
<P>
<font face="Tahoma" style="font-size: 9pt">Please select any of the following <u>Other Services</u> that apply:</font></P>
<BLOCKQUOTE>
<P>
<font face="Tahoma"><span style="font-size: 9pt">
<INPUT TYPE=CHECKBOX NAME="websitedesign" value="0">
Website Design<BR>
<INPUT TYPE=CHECKBOX NAME="logodesign" value="0">
Logo Design<BR>
<INPUT TYPE=CHECKBOX NAME="hrconsulting" value="0">
HR Consulting<BR>
<INPUT TYPE=CHECKBOX NAME="govtcontractor" value="0">
Government Contractor Registration<BR>
<INPUT TYPE=CHECKBOX NAME="_501c3" value="0">
501c3 Setup<BR>
<INPUT TYPE=CHECKBOX NAME="eventsvcs" value="0">
Event Services</span></font><BR>
<INPUT TYPE=CHECKBOX NAME="printingsvcs" value="0">
<font face="Tahoma"><span style="font-size: 9pt">Printing Services</span></font></span></font><BR>
</P>
</BLOCKQUOTE>
<input type=submit name="sent" value="Submit Form" language="JavaScript" onclick="return validate(this)">
<INPUT TYPE=RESET VALUE="Reset Form">
</FORM>




Tailslide -> RE: how to assign check box items to an array (8/22/2005 11:59:18)

BEEEEP Tailslide isn't in right now. She's currently at a "Don't open your big mouth" conference. It's probably a waste of money however.

Please leave a message after the tone. BEEEEP


OK - I've got it working (not live yet - adding the other boxes to the validation routine). Would you like it "accessible" too? (yes is the right answer).




laticca8 -> RE: how to assign check box items to an array (8/22/2005 12:08:16)

sure, tailslide! whatever is best! you're the greatest! [sm=bowdown.gif]




Tailslide -> RE: how to assign check box items to an array (8/22/2005 13:33:23)

Evening!

Here you go:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Request further Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >


</head>
<body>
<script type="text/javascript">
 //<![CDATA[
function validate(tfsinforequest){
{
var contactmethod = document.tfsinforequest.contactmethod;
var email = document.tfsinforequest.email;
var address = document.tfsinforequest.address;
var numBoxes= 0;
if (contactmethod.selectedIndex < 1)
{
alert("Please provide your preferred method of contact.");
contactmethod.focus();
return false;
}
if ((contactmethod.selectedIndex==1) && (email.value == ""))
{
window.alert("Please enter your email address.");
email.focus();
return false;
}
if ((contactmethod.selectedIndex==2) && (address.value == ""))
{
window.alert("Please enter your mailing address.");
address.focus();
return false;
}
	
	for(i=0;i<tfsinforequest.service.length; i++){
		if (tfsinforequest.service.checked){
			numBoxes++;
		}
	}
	
	if (numBoxes < 1){
		alert("Please select at least one Service");
		return false;
	}
		
else {
return true;
}
}}
  //]]>
</script>
<div id="form" style="font: 76% Tahoma, sans-serif;">  <!-- I've put an extra div in here to control the fonts throughout the form -->

<p><form name="tfsinforequest" method="post" action="http://www.tricapacademy.org/tfsinfoconfirm.php" onSubmit="return validate(this);">
<input type="hidden" name="id" value="NULL">
<div align="left">
<h2 style="font-size:150%">Request for More Information</h2>

<table border="0" id="table1" style="font-size:100%; font-weight:bold; text-align:right;"><!-- the styles in this table control font and font-size in the table -->

<tr><td align="right"><label for="name">Name </label></td>
<td align="left"><input id="name" name="name" size=50></td></tr>
<tr><td align="right"><label for="contactmethod">Preferred Contact Method </label></td>
<td align="left"><select id="contactmethod" name="contactmethod" size="1"><option selected value="">Please select one</option>
                                                                                                                                <option value="email">Email</option>
                                                                                                                                <option value="postal">Postal Delivery</option>
                                                                                                                                 </select>
                                                                                                                                 </td></tr>
<tr><td align="right"><label for="email">Email Address* </label></td>
<td align="left"><input id="email" name="email" size=25></td></tr>

<tr><td align="right" valign="top"><label for="address">Postal Address* </label></td>
<td align="left"><textarea id="address" name="address" rows=5 cols=35></textarea></td></tr>

</table></div><!-- end aligned left div -->

<p style="margin-top: 0; font-weight:bold;">* These fields are required only if chosen as the preferred method of contact.</p>

<p><label for="referral">How did you hear about us? </label><select id="referral" name="referral" size="1">
                                                                                                      <option selected value="">Please select one</option>
                                                                                                      <option value="returning">I am a returning customer.</option>
                                                                                                      <option value="referral">Referral from a friend/relative/associate</option>
                                                                                                      <option value="google">Google.com</option>
                                                                                                      <option value="othersearch">Other search engine</option>
                                                                                                      <option value="link">I saw/clicked on your link on another site.</option>
                                                                                                      <option value="other">Other</option>
                                                                                                      </select>
</p>
<p></p>

<p style="font-weight:bold;">I would like to receive additional information about the following services:</p>

<p>Please select any of the following <b>Business Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="service" value="bizstartup" id="bizstartup"><label for="bizstartup">Startup Services</label><br />
<input type=checkbox name="service" value="bizcredit" id="bizcredit"><label for="bizcredit">Credit Services</label><br />
<input type=checkbox name="service" value="taxrecovery" id="taxrecovery"><label for="taxrecovery">Tax Recovery</label><br />
<input type=checkbox name="service" value="strategicplan" id="strategicplan"><label for="strategicplan">Strategic Plan Consulting</label><br />
<input type=checkbox name="service" value="processimprovemt" id="processimprovemt"><label for="processimprovemt">Process Improvement Consulting</label><br />
<input type=checkbox name="service" value="bizaudit" id="bizaudit"><label for="bizaudit">Business Audit</label><br />
</p></blockquote>

<p>Please select any of the following <b>Church Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="service" value="churchfinancing" id="churchfinancing"><label for="churchfinancing">Charitable Gifting</label><br />
<input type=checkbox name="service" value="_501c3setup" id="_501c3setup"><label for="_501c3setup">501c3 Setup</label><br />
</P></blockquote>

<P>Please select any of the following <b>Personal Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="service" value="lifeins" id="lifeins"><label for="lifeins">Burial & Life Insurance</label><br />
<input type=checkbox name="service" value="healthins" id="healthins"><label for="healthins">Health Insurance</label><br />
<input type=checkbox name="service" value="_529plan" id="_529plan"><label for="_529plan">Education Funding</label><br />
<input type=checkbox name="service" value="_401k" id="_401k"><label for="_401k">Retirement Planning</label><br />
<input type=checkbox name="service" value="disabilityins" id="disabilityins"><label for="disabilityins">Disability Insurance</label><br />
</p></blockquote>

<p>Please select any of the following <b>Other Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="service" value="websitedesign" id="websitedesign"><label for="websitedesign">Website Design</label><br />
<input type=checkbox name="service" value="logodesign" id="logodesign"><label for="logodesign">Logo Design</label><br />
<input type=checkbox name="service" value="hrconsulting" id="hrconsulting"><label for="hrconsulting">HR Consulting</label><br />
<input type=checkbox name="service" value="govtcontractor" id="govtcontractor"><label for="govtcontractor">Government Contractor Registration</label><br />
<input type=checkbox name="service" value="_501c3" id="_501c3"><label for="_501c3">501c3 Setup</label><br />
<input type=checkbox name="service" value="eventsvcs" id="eventsvcs"><label for="eventsvcs">Event Services</label><br />
<input type=checkbox name="service" value="printingsvcs" id="printingsvcs"><label for="printingsvcs">Printing Services</label><br />
</p></blockquote>

<p><input type=submit name="sent" value="Submit Form"></p>

</form>

</div><!-- end of form div  -->

</body>
</html>


Might be easier to copy it from here though: Tailslide's fiendish test page!

It's more accessible now (I've put <label> tags in for each input item and although I tend to leave tables out of forms just in case they confuse people - I've left them in here as you had them and it might confuse the structure of your page if I took them out!. Got rid of all the font tags - included the text size/font details with in-line CSS instead - takes about half the code out!!

The page validates to HTML 4.01 transitional except for some of your attribute names which start with an underscore which the validator doesn't like. If that bothers you then change the names. Tested in Firefox and IE and seems to work fine.

Oh I forgot to say that I took out the reset button - this is purely my own opinion but I think they're a waste of time - how many times have you ever actually pressed reset to blank a form you're filling in? You go back and change something sure - but wipe the lot? What does often happen is that you press reset by accident having written "War and Peace" in your form - and sometimes you're so p****d off at yourself and the form that you don't bother filling it again! Feel free to put it back in if you prefer.




laticca8 -> RE: how to assign check box items to an array (8/22/2005 13:38:34)

i love you! i haven't included the code yet, but just the fact that you went through all this trouble is remarkable. i truly appreciate it!

i took a peek at your website too! your designs are so nice, clean, and professional!




Tailslide -> RE: how to assign check box items to an array (8/22/2005 13:41:14)

[img]http://www.crackmanworld.com/inc/libs/editor_files/images/smileys/smiley9.gif[/img]







laticca8 -> RE: how to assign check box items to an array (8/22/2005 14:31:17)

thank you soooooo much, tailslide! you are so good at this and a great helper! one day i hope to be as knowledgeable as some of you more experienced designers.

oh well, i suppose it comes with time! as a newbie, though, i truly appreciate your going out of the way, the extra mile to help me!

as i like to say these days, just continue to "do what you do!" [sm=angel.gif]




Tailslide -> RE: how to assign check box items to an array (8/22/2005 14:34:13)

I'm assuming it's working for you then? (phew!)

It's no problem - I actually like trying to figure this stuff out - Javascript is not one of my strong points so doing this helps me learn.

Besides - I'm sneakilly spreading my accessibility message - maybe next time you do a form you'll use <label> etc!!

[:D]




laticca8 -> RE: how to assign check box items to an array (8/22/2005 15:35:41)

yeah, i tested it on my intranet and it worked fine. i just have to upload it to the "real" site.

i have to study that script for future reference. i love what you did with the line to apply fonts throughout the form. i saw the labels too and was a little confused. i'll definitely study it though.




laticca8 -> RE: how to assign check box items to an array (8/22/2005 15:40:56)

oh, i just reread one of your prior posts. yeah, i see what you're saying about the reset button. i wondered why it was missing (reading is fundamental, huh?). anywho, that's a point well taken and i'll omit it.





Tailslide -> RE: how to assign check box items to an array (8/22/2005 16:00:07)

quote:

ORIGINAL: laticca8
i love what you did with the line to apply fonts throughout the form. i saw the labels too and was a little confused. i'll definitely study it though.


The "line" was CSS (Cascading Style Sheets) you basically just write a "rule" for whatever - a paragraph, a table, a photo - anything and say how you want it to look and be laid out. You can use this in place of tables for laying out a page. Ideally it should be in a separate document called an "external stylesheet" then if you wanted to change the font on your site for instance you change it once in that stylesheet it will apply globally throughout your site. Going in and changing thousands of <font> tags suddenly looks less appealing!

The <label> tag is to help people who might be using a text reader to look at your site - forms can be very confusing if the "label" of the input field is not obvious - the <label> tag forms an association between the label and the input field itself.

Funny thing about the Reset Button - it's just always added - used to put them in myself. Then one day I read an article saying that they were pointless and it dawned on me that I've never ever used one (apart from when I'm testing my own forms!). I have hit it by accident quite a few times though!




laticca8 -> RE: how to assign check box items to an array (8/22/2005 16:04:30)

oh, okay. i've used CSS in my other website. i see now. it makes perfect sense.

yeah, i thought the reset button was just form protocol.

thanks for "schooling" me on the label stuff too!




laticca8 -> RE: how to assign check box items to an array (8/22/2005 22:23:55)

tailslide, i thought this was resolved, but it isn't. i guess since the name of all the checkboxes is the same (service), the selections do not post to the database.

it does validate, but there are no "0"s in the appropriate column for the selected service. [&:]

for reference, the page that posts the variables has the following script:

<?
if ($_POST["sent"] == "Submit Form")
{
$DBhost = "localhost";
$DBuser = "********";
$DBpass = "********";
$DBName = "********";
$table = "information";
$id = $_POST['id'];
$name = $_POST['name'];
$contactmethod = $_POST['contactmethod'];
$email = $_POST['email'];
$address = $_POST['address'];
$referral = $_POST['referral'];
$bizstartup = $_POST['bizstartup'];
$bizcredit = $_POST['bizcredit'];
$_501c3setup = $_POST['_501c3setup'];
$_529plan = $_POST['_529plan'];
$_401k = $_POST['_401k'];
$disabilityins = $_POST['disabilityins'];
$string1 = "Thank you for your interest!";
$string2 = "We will promptly send the requested information to";
$string3 = "We look forward to working with you!";


mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table VALUES('$id','$name','$contactmethod','$email','$address','$referral','$bizstartup','$bizcredit','$_501c3setup','$_529plan','$_401k','$disabilityins',NOW())";

$results = mysql_query($sqlquery);

mysql_close();

if ($contactmethod == "Email")
{
echo "$string1 $string2 $email.<br><br>";
}
else
{
echo "$string1 $string2 $address.<br><br>";
}
echo "$string3";
}
?>




Tailslide -> RE: how to assign check box items to an array (8/23/2005 1:44:26)

Oops - didn't realise you were saving it to a db and needed the specific "0" value!

I've replaced all the "values" with "0" - is that correct, that all the values should be "0"?

Anyway - here you go again! http://www.littleblueplane.com/test/checkboxformtest5.html




laticca8 -> RE: how to assign check box items to an array (8/23/2005 1:55:39)

the values still aren't posting. i went through and checked them all and none of the columns displayed a "0" in the database. [:(]

i wonder is it because the names for each is "service"? i know this is probably necessary to create an array, though.

i'm so sorry this turned out to be much more than you bargained for. [&:]




Tailslide -> RE: how to assign check box items to an array (8/23/2005 2:47:02)

Ok ok I think I got it! (this'd be much much easier if I knew more about JS - rather than just trial and error - mostly error!)

http://www.littleblueplane.com/test/checkboxformtest6.html

This has got the values of all the checkboxes at 0 plus the names of each checkbox are back to the individual ones rather than just service.

To validate them I've had to get it to go through each of 'em and check that one is ticked.

Hopefully this works!!

If not I'll have another go later - I've got a client to see this morning so I'll be busy.

<script type="text/javascript">
 //<![CDATA[
function validate(tfsinforequest){
{
var contactmethod = document.tfsinforequest.contactmethod;
var email = document.tfsinforequest.email;
var address = document.tfsinforequest.address;
var numBoxes= 0;
if (contactmethod.selectedIndex < 1)
{
alert("Please provide your preferred method of contact.");
contactmethod.focus();
return false;
}
if ((contactmethod.selectedIndex==1) && (email.value == ""))
{
window.alert("Please enter your email address.");
email.focus();
return false;
}
if ((contactmethod.selectedIndex==2) && (address.value == ""))
{
window.alert("Please enter your mailing address.");
address.focus();
return false;
}
if ( ( document.tfsinforequest.bizstartup.checked == false  )
    && ( document.tfsinforequest.bizcredit.checked == false  )
		&& ( document.tfsinforequest.taxrecovery.checked == false  )
		&& ( document.tfsinforequest.strategicplan.checked == false  )
		&& ( document.tfsinforequest.processimprovemt.checked == false  )
		&& ( document.tfsinforequest.bizaudit.checked == false  )
		&& ( document.tfsinforequest.churchfinancing.checked == false  )
    && ( document.tfsinforequest._501c3setup.checked == false  )
    && ( document.tfsinforequest.lifeins.checked == false  )
    && ( document.tfsinforequest._401k.checked == false  )
    && ( document.tfsinforequest.healthins.checked == false  )
    && ( document.tfsinforequest.disabilityins.checked == false  )
    && ( document.tfsinforequest._529plan.checked == false  )
    && ( document.tfsinforequest.websitedesign.checked == false  )
		&& ( document.tfsinforequest.logodesign.checked == false  )
		&& ( document.tfsinforequest.hrconsulting.checked == false  )
		&& ( document.tfsinforequest.govtcontractor.checked == false  )
		&& ( document.tfsinforequest._501c3.checked == false  )
		&& ( document.tfsinforequest.eventsvcs.checked == false  )
		&& ( document.tfsinforequest.printingsvcs.checked == false  )){
        
				alert ( "Please Pick a service" );
        return false;
 }
		
else {
return true;
}
}}
  //]]>
</script>
<div id="form" style="font: 76% Tahoma, sans-serif;">  <!-- I've put an extra div in here to control the fonts throughout the form -->

<p><form name="tfsinforequest" method="post" action="http://www.tricapacademy.org/tfsinfoconfirm.php" onSubmit="return validate(this);">
<input type="hidden" name="id" value="NULL">
<div align="left">
<h2 style="font-size:150%">Request for More Information</h2>

<table border="0" id="table1" style="font-size:100%; font-weight:bold; text-align:right;"><!-- the styles in this table control font and font-size in the table -->

<tr><td align="right"><label for="name">Name </label></td>
<td align="left"><input id="name" name="name" size=50></td></tr>
<tr><td align="right"><label for="contactmethod">Preferred Contact Method </label></td>
<td align="left"><select id="contactmethod" name="contactmethod" size="1"><option selected value="">Please select one</option>
                                                                                                                                <option value="email">Email</option>
                                                                                                                                <option value="postal">Postal Delivery</option>
                                                                                                                                 </select>
                                                                                                                                 </td></tr>
<tr><td align="right"><label for="email">Email Address* </label></td>
<td align="left"><input id="email" name="email" size=25></td></tr>

<tr><td align="right" valign="top"><label for="address">Postal Address* </label></td>
<td align="left"><textarea id="address" name="address" rows=5 cols=35></textarea></td></tr>

</table></div><!-- end aligned left div -->

<p style="margin-top: 0; font-weight:bold;">* These fields are required only if chosen as the preferred method of contact.</p>

<p><label for="referral">How did you hear about us? </label><select id="referral" name="referral" size="1">
                                                                                                      <option selected value="">Please select one</option>
                                                                                                      <option value="returning">I am a returning customer.</option>
                                                                                                      <option value="referral">Referral from a friend/relative/associate</option>
                                                                                                      <option value="google">Google.com</option>
                                                                                                      <option value="othersearch">Other search engine</option>
                                                                                                      <option value="link">I saw/clicked on your link on another site.</option>
                                                                                                      <option value="other">Other</option>
                                                                                                      </select>
</p>
<p></p>

<p style="font-weight:bold;">I would like to receive additional information about the following services:</p>

<p>Please select any of the following <b>Business Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="bizstartup" value="0" id="bizstartup"><label for="bizstartup">Startup Services</label><br />
<input type=checkbox name="bizcredit" value="0" id="bizcredit"><label for="bizcredit">Credit Services</label><br />
<input type=checkbox name="taxrecovery" value="0" id="taxrecovery"><label for="taxrecovery">Tax Recovery</label><br />
<input type=checkbox name="strategicplan" value="0" id="strategicplan"><label for="strategicplan">Strategic Plan Consulting</label><br />
<input type=checkbox name="processimprovemt" value="0" id="processimprovemt"><label for="processimprovemt">Process Improvement Consulting</label><br />
<input type=checkbox name="bizaudit" value="0" id="bizaudit"><label for="bizaudit">Business Audit</label><br />
</p></blockquote>

<p>Please select any of the following <b>Church Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="churchfinancing" value="0" id="churchfinancing"><label for="churchfinancing">Charitable Gifting</label><br />
<input type=checkbox name="_501c3setup" value="0" id="_501c3setup"><label for="_501c3setup">501c3 Setup</label><br />
</P></blockquote>

<P>Please select any of the following <b>Personal Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="lifeins" value="0" id="lifeins"><label for="lifeins">Burial & Life Insurance</label><br />
<input type=checkbox name="healthins" value="0" id="healthins"><label for="healthins">Health Insurance</label><br />
<input type=checkbox name="_529plan" value="0" id="_529plan"><label for="_529plan">Education Funding</label><br />
<input type=checkbox name="_401k" value="0" id="_401k"><label for="_401k">Retirement Planning</label><br />
<input type=checkbox name="disabilityins" value="0" id="disabilityins"><label for="disabilityins">Disability Insurance</label><br />
</p></blockquote>

<p>Please select any of the following <b>Other Services</b> that apply:</p>

<blockquote><p>
<input type=checkbox name="websitedesign" value="0" id="websitedesign"><label for="websitedesign">Website Design</label><br />
<input type=checkbox name="logodesign" value="0" id="logodesign"><label for="logodesign">Logo Design</label><br />
<input type=checkbox name="hrconsulting" value="0" id="hrconsulting"><label for="hrconsulting">HR Consulting</label><br />
<input type=checkbox name="govtcontractor" value="0" id="govtcontractor"><label for="govtcontractor">Government Contractor Registration</label><br />
<input type=checkbox name="_501c3" value="0" id="_501c3"><label for="_501c3">501c3 Setup</label><br />
<input type=checkbox name="eventsvcs" value="0" id="eventsvcs"><label for="eventsvcs">Event Services</label><br />
<input type=checkbox name="printingsvcs" value="0" id="printingsvcs"><label for="printingsvcs">Printing Services</label><br />
</p></blockquote>

<p><input type=submit name="sent" value="Submit Form"></p>

</form>

</div><!-- end of form div  -->




laticca8 -> RE: how to assign check box items to an array (8/23/2005 8:30:13)

believe it or not, this is exactly what i was about to attempt to do before i read this message. i'm sure this will work; of course, i'll let you know! thank you so much! [:D]




laticca8 -> RE: how to assign check box items to an array (8/23/2005 8:46:52)

absolutely perfect! this time it works without a doubt! all fields are validating correctly and the selections are posted to the database! thanks a billion!

good luck with the client! [;)]




Tailslide -> RE: how to assign check box items to an array (8/23/2005 9:01:07)

Phew - glad it worked! [:D]




laticca8 -> RE: how to assign check box items to an array (8/23/2005 9:41:39)

[sm=bowdown.gif] hope you learned something at the "don't open your big mouth conference!" [:D]

thanks again, though! this has truly been an adventure! it's fun, though! [sm=yupi3ti.gif]




Reflect -> RE: how to assign check box items to an array (8/23/2005 10:31:27)

Tailside....

Thank you.

I researched and now see why to use them normally. More clickable space on the control. Further research showed accessibility issues it helps with. It makes sense.

I will recode my forms this weekend to add this feature.

Thank you for opening my eyes to this.

Take care,

Brian




Tailslide -> RE: how to assign check box items to an array (8/23/2005 11:08:00)

I always forget about that being another plus point for <label> thanks for reminding me Brian! [:D]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.15625