PC Review


Reply
Thread Tools Rate Thread

check checkbox submit

 
 
Mark
Guest
Posts: n/a
 
      9th Feb 2004
Hi,
I use javascript to force the user to
click checkbox when they click submit.
It works well when checkbox is more
than one. If only one checkbox, it doesn't
want me go through. I think my javascript
has some logic problem. but I don't know
how to modify it. Anyone can help me.
Thanks,



<html>
<head>
<title>Delete</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function DeleteInventory(){
for (var i=0; i<document.forms[0].batchdeletes.length; i++) {
if(document.forms[0].batchdeletes[i].checked){
if (confirm("This will delete Inventories you selected!")){
document.forms[0].action = "http://www.yahoo.com";
document.forms[0].submit();
return true;
}
else{
return false;
}
}
}
alert('You must check the checkbox');
return false;
}

// -->
</SCRIPT>
</head>
<body>
<form name="delete_inv" method="POST">
<p>
<input type="checkbox" name="batchdeletes" value="A123"><br>
<!--input type="checkbox" name="batchdeletes" value="A124"--><br>
<!--input type="checkbox" name="batchdeletes" value="A125"--><br>
<input type=button name=deletebutton value="Delete Selected Inventories"
onclick="return DeleteInventory();">
</p>
</form>
</body>
</html>




 
Reply With Quote
 
 
 
 
Jim Buyens
Guest
Posts: n/a
 
      9th Feb 2004
Howdy.

I think you'll need to count selected checkboxes, and then
test the count. For example:

cnt = 0;
for (i=0; i<document.forms[0].batchdeletes.length; i++) {
if(document.forms[0].batchdeletes[i].checked){
cnt = cnt + 1;
}
}
if (cnt > 0){
if (confirm(
"This will delete Inventories you selected!")){
document.forms[0].action = "http://www.yahoo.com";
document.forms[0].submit();
return true;
}else{
return false;
}
}else{
alert('You must select at least one checkbox');
return false;
}

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------


>-----Original Message-----
>Hi,
>I use javascript to force the user to
>click checkbox when they click submit.
>It works well when checkbox is more
>than one. If only one checkbox, it doesn't
>want me go through. I think my javascript
>has some logic problem. but I don't know
>how to modify it. Anyone can help me.


>Thanks,
>
>
>
><html>
><head>
><title>Delete</title>
><SCRIPT LANGUAGE="JavaScript">
><!--
>function DeleteInventory(){
> > if (confirm("This will delete Inventories you

selected!")){
> document.forms[0].action = "http://www.yahoo.com";
> document.forms[0].submit();
> return true;
> }
> else{
> return false;
> }
> }
> }
> alert('You must check the checkbox');
> return false;
>}
>
>// -->
></SCRIPT>
></head>
><body>
><form name="delete_inv" method="POST">
> <p>
> <input type="checkbox" name="batchdeletes"

value="A123"><br>
> <!--input type="checkbox" name="batchdeletes"

value="A124"--><br>
> <!--input type="checkbox" name="batchdeletes"

value="A125"--><br>
> <input type=button name=deletebutton value="Delete

Selected Inventories"
>onclick="return DeleteInventory();">
> </p>
></form>
></body>
></html>
>
>
>
>
>.
>

 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      9th Feb 2004
Jim,
The code didn't work.
Thanks,



<html>
<head>
<title>Delete</title>
<SCRIPT LANGUAGE="JavaScript">
<!--

function DeleteInventory(){
cnt = 0;
for (i=0; i<document.forms[0].batchdeletes.length; i++) {
if(document.forms[0].batchdeletes[i].checked){
cnt = cnt + 1;
}
}
if (cnt > 0){
if (confirm(
"This will delete Inventories you selected!")){
document.forms[0].action = "http://www.yahoo.com";
document.forms[0].submit();
return true;
}else{
return false;
}
}else{
alert('You must select at least one checkbox');
return false;
}
}
// -->
</SCRIPT>
</head>
<body>
<form name="delete_inv" method="POST">
<p>
<input type="checkbox" name="batchdeletes" value="A123"><br>
<!--input type="checkbox" name="batchdeletes" value="A124"--><br>
<input type=button name=deletebutton value="Delete Selected Inventories"
onclick="return DeleteInventory();">
</p>
</form>
</body>
</html>










"Jim Buyens" <(E-Mail Removed)> wrote in message
news:d32901c3ef36$7bbbbf00$(E-Mail Removed)...
> Howdy.
>
> I think you'll need to count selected checkboxes, and then
> test the count. For example:
>
> cnt = 0;
> for (i=0; i<document.forms[0].batchdeletes.length; i++) {
> if(document.forms[0].batchdeletes[i].checked){
> cnt = cnt + 1;
> }
> }
> if (cnt > 0){
> if (confirm(
> "This will delete Inventories you selected!")){
> document.forms[0].action = "http://www.yahoo.com";
> document.forms[0].submit();
> return true;
> }else{
> return false;
> }
> }else{
> alert('You must select at least one checkbox');
> return false;
> }
>
> Jim Buyens
> Microsoft FrontPage MVP
> http://www.interlacken.com
> Author of:
> *----------------------------------------------------
> |\---------------------------------------------------
> || Microsoft Office FrontPage 2003 Inside Out
> ||---------------------------------------------------
> || Web Database Development Step by Step .NET Edition
> || Microsoft FrontPage Version 2002 Inside Out
> || Faster Smarter Beginning Programming
> || (All from Microsoft Press)
> |/---------------------------------------------------
> *----------------------------------------------------
>
>
> >-----Original Message-----
> >Hi,
> >I use javascript to force the user to
> >click checkbox when they click submit.
> >It works well when checkbox is more
> >than one. If only one checkbox, it doesn't
> >want me go through. I think my javascript
> >has some logic problem. but I don't know
> >how to modify it. Anyone can help me.

>
> >Thanks,
> >
> >
> >
> ><html>
> ><head>
> ><title>Delete</title>
> ><SCRIPT LANGUAGE="JavaScript">
> ><!--
> >function DeleteInventory(){
> > > if (confirm("This will delete Inventories you

> selected!")){
> > document.forms[0].action = "http://www.yahoo.com";
> > document.forms[0].submit();
> > return true;
> > }
> > else{
> > return false;
> > }
> > }
> > }
> > alert('You must check the checkbox');
> > return false;
> >}
> >
> >// -->
> ></SCRIPT>
> ></head>
> ><body>
> ><form name="delete_inv" method="POST">
> > <p>
> > <input type="checkbox" name="batchdeletes"

> value="A123"><br>
> > <!--input type="checkbox" name="batchdeletes"

> value="A124"--><br>
> > <!--input type="checkbox" name="batchdeletes"

> value="A125"--><br>
> > <input type=button name=deletebutton value="Delete

> Selected Inventories"
> >onclick="return DeleteInventory();">
> > </p>
> ></form>
> ></body>
> ></html>
> >
> >
> >
> >
> >.
> >



 
Reply With Quote
 
Jim Buyens
Guest
Posts: n/a
 
      9th Feb 2004
"Mark" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Jim,
> The code didn't work.
> Thanks,
>
>
>
> <html>
> <head>
> <title>Delete</title>
> <SCRIPT LANGUAGE="JavaScript">
> <!--
>
> function DeleteInventory(){
> cnt = 0;
> for (i=0; i<document.forms[0].batchdeletes.length; i++) {
> if(document.forms[0].batchdeletes[i].checked){
> cnt = cnt + 1;
> }
> }
> if (cnt > 0){
> if (confirm(
> "This will delete Inventories you selected!")){
> document.forms[0].action = "http://www.yahoo.com";
> document.forms[0].submit();
> return true;
> }else{
> return false;
> }
> }else{
> alert('You must select at least one checkbox');
> return false;
> }
> }
> // -->
> </SCRIPT>
> </head>
> <body>
> <form name="delete_inv" method="POST">
> <p>
> <input type="checkbox" name="batchdeletes" value="A123"><br>
> <!--input type="checkbox" name="batchdeletes" value="A124"--><br>
> <input type=button name=deletebutton value="Delete Selected Inventories"
> onclick="return DeleteInventory();">
> </p>
> </form>
> </body>
> </html>



Whoops! I didn't notice that you had the "A124" checkbox commented
out. If you change it to

<input type="checkbox" name="batchdeletes" value="A124">

then batchdeletes will be an array and the code will work.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check whether user put a check in a toolbox CheckBox contro JB Microsoft ASP .NET 1 27th Aug 2009 12:18 AM
Unbound checkbox on datasheet subform - check one and they all check Robert Microsoft Access Forms 6 1st Jan 2008 05:21 PM
all the check boxes should be checked if i check a particular checkbox in that row rg.ruchigoel@gmail.com Microsoft Excel Programming 3 18th Apr 2007 09:20 AM
One CheckBox. one ImageButton. Why I can't force the user to click the agreement before submit form? Benny Ng Microsoft ASP .NET 4 23rd May 2006 03:52 PM
submit checkbox to database Bizi Microsoft Frontpage 0 13th Jul 2003 10:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:47 PM.