pcalabria
asked on
Very basic HTML checkbox problem
Hello Experts, thanks in advance.
I've new to Javascript and just can't figure this out!
I have an Order Form that consists of a variable number of rows.
The customer simply checks a checkbox to select which items he wants.
The problem I am having is that if a checkbox is not checked, then no value is returned.
Here's some sample code. While the code below only includes two line items, the actual number may vary from 1 to any number of rows.
mypage.asp must have code to extract the part number and qty for each item selected.
If there's a way for a checkbox to return not checked this job would be easy.
My code on the mypage.asp loops through the querystring collection, but returns an error when a value of checkbox that is not checked is encountered.
''''Code Below"""
<form action="mypage.asp" method="get">
Qty<input name="Qty" type="text" />
Part Number<input name="PartNumber" type="text" />
<input type="checkbox" name="buyme" value="yes" /><br /><br />
Qty<input name="Qty" type="text" />
Part Number<input name="PartNumber" type="text" />
<input type="checkbox" name="buyme" value="yes" /><br /><br />
<input name="Update" type="submit" />
</form>
I've new to Javascript and just can't figure this out!
I have an Order Form that consists of a variable number of rows.
The customer simply checks a checkbox to select which items he wants.
The problem I am having is that if a checkbox is not checked, then no value is returned.
Here's some sample code. While the code below only includes two line items, the actual number may vary from 1 to any number of rows.
mypage.asp must have code to extract the part number and qty for each item selected.
If there's a way for a checkbox to return not checked this job would be easy.
My code on the mypage.asp loops through the querystring collection, but returns an error when a value of checkbox that is not checked is encountered.
''''Code Below"""
<form action="mypage.asp" method="get">
Qty<input name="Qty" type="text" />
Part Number<input name="PartNumber" type="text" />
<input type="checkbox" name="buyme" value="yes" /><br /><br />
Qty<input name="Qty" type="text" />
Part Number<input name="PartNumber" type="text" />
<input type="checkbox" name="buyme" value="yes" /><br /><br />
<input name="Update" type="submit" />
</form>
this script wil give you the checkboxes that are not checked
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function ex(obj)
{
for(var i=0;i<document.getElementsByName("buyme").length;i++)
{
if(!document.getElementsByName("buyme")[i].checked)
alert('not checked..'+document.getElementsByName("buyme")[i].value)
}
}
</script>
</HEAD>
<BODY>
<form action="mypage.asp" method="get">
Qty<input name="Qty" type="text" />
Part Number<input name="PartNumber" type="text" />
<input type="checkbox" name="buyme" value="1" /><br /><br />
Qty<input name="Qty" type="text" />
Part Number<input name="PartNumber" type="text" />
<input type="checkbox" name="buyme" value="2"/><br /><br />
<input name="Update" type="button" value='button' onclick='ex()'/>
</form>
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I solved the problem by naming the checkbox variable using the row sequence number as its name, and then creating a recordset of just the checkbox items on the page that recieved the get.
So lets say there were 10 rows and two were selected, the recordset of checkbox items would include just two items, and the value of these two items provide the index numbers of the selected rows.
So lets say there were 10 rows and two were selected, the recordset of checkbox items would include just two items, and the value of these two items provide the index numbers of the selected rows.
Open in new window
Open in new window