akasotia@guidemail.com (Andy) wrote in message news:<acd1015f.0410061121.1b0d42fb@posting.google. com>...[color=blue]
> I'm not sure why my checkbox code is not working as per intended. It
> always keeps saying "Please select the department" even though I check
> the department... appreciate any help.
>[/color]
I made some comments in the text.
Do not know why [X] by itself wasn't giving an error. I changed them
to just x.
You may want to try out firefox. It has a dom inspector which will
let you see the generated html.
The following one-liner when pasted into the command line will also
display the generated html. (It looks for line ends which are OS
dependent.):
javascript
:'<html><head><title>SourceFileListing<\/title><\/head><body><code><ol><li>'+(document.documentEleme nt||document.body).innerHTML.replace(/&/g,%22&%22).replace(/</g,%22<%22).replace(/%20%20/g,%22 %20%22).replace(/\r\n/g,%22<li>%22).replace(/\n/g,%22<li>%22).replace(/\r/g,%22<li>%22)+'<\/ol><\/code><\/body><\/html>';
Robert
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><TITLE>Welcome to the Scripting Store</TITLE>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
<script type="text/javascript">
// Notice the change in the doctype and script tag.
/* Good that you post your javascript with short lines.
Seems like you have experience with programming.
*/
// Banner Rotator logic
//Load banner elements into array
// Here is another syntax for arrays...
var banners = [ "banner1.jpg",
"banner2.jpg",
"banner3.jpg",
"banner4.jpg" ];
//Set banner counter to 0
var bnrCntr = 0
//Function that actually rotates the banner
function bancycle() {
bnrCntr = bnrCntr + 1
if (bnrCntr == 4) {
bnrCntr = 0
}
document.Banner.src = banners[bnrCntr]
setTimeout("bancycle()",3000)
}
//End Banner Rotator Logic
</SCRIPT>
<!-- What is this. Be careful about using html generators and
Javascript. Be doubly careful with MS products. -->
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<!-- need quote marks around event handler code
The ; is recommended. -->
<BODY onload="bancycle();">
<TABLE borderColor=blue width=700 border=1>
<TBODY>
<TR>
<TD width="30%"><IMG name=Banner></TD>
<TD align=middle>
<H1>Welcome to the Scripting
Store</H1></TD></TR></TBODY></TABLE><BR>
<!-- try to minimize javascript inline. Call a function. -->
<SCRIPT language=javascript>
document.writeln("Today is: ");
var nDate = new Date();
document.writeln(nDate);
var strName = new String();
strName = window.prompt("What is your Name?", "FirstNameOnly");
//document.write("Welcome " + strName + "<br>");
document.write("<h2>Hello " + strName + "</h2>");
var varStatus;
status = "Hello " + strName + " - Welcome to the Scripting Store";
//Year(Now());
</SCRIPT>
<!-- Add form tag. -->
<form name="myform">
<!-- I'd move the button below the check boxes. Watch you
eye movement for the why. -->
<P>Please select one of our departments listed below</P><BR><INPUT
onclick=locateDepartment() type=button value="Select Department"
name=btnSelect>
<BR>
<SCRIPT>
var varDept = new Array(3);
varDept[0] = "Books";
varDept[1] = "Computers";
varDept[2] = "Caffeine free products";
var numMax = varDept.length;
var strDept;
<!-- I'd go with varDept.length in the code. -->
for (var i=0; i <numMax; ++i)
{
/* Missing signal quotes for value and name.
Sometimes you need the quote marks and sometimes you
can luck out. So, allows do. */
document.write("<p><input type='checkbox' value='" + i + "' name='" +
varDept[i] + "'>" + varDept[i] + "</p>");
}
</SCRIPT>
</form>
<SCRIPT>
function locateDepartment()
{
/* I'm not sure that the loop saves you any code. */
var varselect = true;
var varMax = 3;
for (var x=0; x < varMax; ++x)
{
/* Try puting in alerts for debug. */
alert("x= " + x);
/* Need to reference the form */
if (document.forms["myform"].elements[varDept[x]].checked == true)
{
if (x == 0)
{
location.href='book.htm';
}
else if (x == 1)
{
location.href='Caffiene.htm';
}
else if (x == 2)
{
location.href='Computers.htm';
}
}
else
{
varselect = false;
}
}
if (varselect == false)
{
window.alert("Please Select a Department");
return false;
}
}
</SCRIPT>
</BODY></HTML>