Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 27th, 2003, 03:21 PM
Authorized User
 
Join Date: Oct 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to control two checkboxes

How can I control two checkboxes with different names. I want to check only one checkbox at a time.

Thanks.

Reply With Quote
  #2 (permalink)  
Old October 27th, 2003, 03:45 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What exactly do you mean by "control two checkboxes with different names"

If you only need to hceck one item at a time, create radio buttons. (option Buttons/ option group).

It is not good programming to change the meaning of a checkbox to act as a option group.

Sal
Reply With Quote
  #3 (permalink)  
Old October 27th, 2003, 04:21 PM
Authorized User
 
Join Date: Oct 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used to use the following codes for the controlling 2 checkboxes.
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
function checkBoxValidate(cb) {
for (j = 0; j < 2; j++) {
if (eval("document.myform.ckbox[" + j + "].checked") == true) {
document.myform.ckbox[j].checked = false;
if (j == cb) {
document.myform.ckbox[j].checked = true;
         }
     }
}
}
</script>

</HEAD>
</head>

<body>

<BODY>

<form name=myform action ="NextPage.asp">
Selection 1<input type="checkbox" name="ckbox" onClick="javascript:checkBoxValidate(0)"><br>
Selection 2<input type="checkbox" name="ckbox" onClick="javascript:checkBoxValidate(1)"><br>

---------------------------------------------------------------

Now I have been working with this code:

<form name="MyForm" METHOD="Post" ACTION="NextPage.asp
<table><tr>
<td>font size=3><b>Root Cause:</b>
<input TYPE="checkbox" NAME="RootCause"></td>
<td><b>Fin Approval:</b>
<input TYPE="checkbox" NAME="FinApproval"></td>
</tr></table>

In the NextPage.asp:
<%if Request.form("FinApproval") = "on" then%>
STATEMENT1.......
<%end if%>
<%if Request.form("RootCause") = "on" then%>
STATEMENT2.......
<%end if%>

Is there any way that I can control the checkbox( means check only one checkbox at a time like radio button)with different checkbox names or any suggestion is welcome,

Thanks...
Reply With Quote
  #4 (permalink)  
Old October 27th, 2003, 04:47 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use radio button. Do not confuse users.

Radio buttons = select one
chechbox = select multiples.

do not change the rules

Sal
Reply With Quote
  #5 (permalink)  
Old October 27th, 2003, 05:02 PM
Authorized User
 
Join Date: Oct 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any possiblitiy to unclick radio button then? As I know of, you can't unclick radio buttons without resetting the whole form. User has chance to click/unclick without reseting the whole form using the checkboxes. That's why I would like to use checkbox. Am I missing something?
Reply With Quote
  #6 (permalink)  
Old October 27th, 2003, 06:22 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you try setting the value to 0?

Sal
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
treeview control with checkboxes in asp.net 1.1 sandeep_345 General .NET 0 June 9th, 2006 01:56 AM
Help needed with CheckBoxes saravanan_article C# 0 March 8th, 2006 09:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.