473,782 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic checkboxes

1 New Member
Hello!

I need help to modify the following javascript:

[HTML]<script language="javas cript">

var flds = "chk1,chk2,chk3 ,chk4".split(", ")
var vals = new Array(2,4,8,16)
var msgs = new Array();

msgs[0] = 'None checked';

msgs[2] = '1 checked';

msgs[4] = '2 checked';
msgs[6] = '2 & 1 checked';

msgs[8] = '3 checked';
msgs[10] = '3 & 1 checked';
msgs[12] = '3 & 2 checked';
msgs[14] = '3 & 2 & 1 checked';

msgs[16] = '4 checked';
msgs[18] = '4 & 1 checked';
msgs[20] = '4 & 2 checked';
msgs[22] = '4 & 2 & 1 checked';
msgs[24] = '4 & 3 checked';
msgs[26] = '4 & 3 & 1 checked';
msgs[28] = '4 & 3 & 2 checked';
msgs[30] = '4 & 3 & 2 & 1 checked';

function chkBoxProc (fld) {
var val = 0;

for (i=0;i<flds.len gth;i++) {
val += (fld.form.eleme nts[flds[i]].checked)?vals[i]:0;
}
document.getEle mentById ('msg').innerHT ML = msgs[val];

}
</script>
<form>
<input type="checkbox" name="chk1" onClick="chkBox Proc(this)">1<b r />
<input type="checkbox" name="chk2" onClick="chkBox Proc(this)">2<b r />
<input type="checkbox" name="chk3" onClick="chkBox Proc(this)">3<b r />
<input type="checkbox" name="chk4" onClick="chkBox Proc(this)">4<b r />

<span id="msg">None checked</span>

</form>[/HTML]

In the end I have about 10 checkboxes, which I want to display by this method. When I wrote this script in the way as you can see above it would take me at least 3 weeks.

Who can help me out to make the script more dynamic?

Finally I would replace the array values with some html-code which contains more form elements (checkboxes...) - is that possible too?

Thank you!
-w
Nov 19 '06 #1
1 4584
sheenattt
20 New Member
Honestly speaking you didnt explained your problem specifically,I didnt understand what ur problem is,but as far as I understood am sending this code.Hope it will help u.

<html>
<title>CodeAve. com(Checkbox Input Validation)</title>
<body bgcolor="#FFFFF F">

<script Language="JavaS cript">
<!--
function checkbox_checke r()
{

// set var checkbox_choice s to zero

var checkbox_choice s = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_form.c heckbox.length; counter++)
{

// If a checkbox has been selected it will return true
// (If not it will return false)
if (checkbox_form. checkbox[counter].checked)
{ checkbox_choice s = checkbox_choice s + 1; }

}


if (checkbox_choic es > 3 )
{
// If there were more than three selections made display an alert box
msg="You're limited to only three selections.\n"
msg=msg + "You have made " + checkbox_choice s + " selections.\n"
msg=msg + "Please remove " + (checkbox_choic es-3) + " selection(s)."
alert(msg)
return (false);
}


if (checkbox_choic es < 3 )
{
// If there were less then selections made display an alert box
alert("Please make three selections. \n" + checkbox_choice s + " entered so far.")
return (false);
}

// If three were selected then display an alert box stating input was OK
alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}

-->
</script>


<form method="get" action="#"
onsubmit="retur n checkbox_checke r()" name="checkbox_ form">
<input type="checkbox" value="A" name="checkbox" >A<br>
<input type="checkbox" value="B" name="checkbox" >B<br>
<input type="checkbox" value="C" name="checkbox" >C<br>
<input type="checkbox" value="D" name="checkbox" >D<br>
<input type="checkbox" value="E" name="checkbox" >E<br>
<input type="checkbox" value="F" name="checkbox" >F<br>
<input type="checkbox" value="G" name="checkbox" >G<br>
<input type="checkbox" value="H" name="checkbox" >H<br>
<input type="checkbox" value="I" name="checkbox" >I<br>
<input type="checkbox" value="J" name="checkbox" >J<br>
<input type="checkbox" value="K" name="checkbox" >K<br>
<input type="checkbox" value="L" name="checkbox" >L<br>
<input type="checkbox" value="M" name="checkbox" >M<br>
<input type="checkbox" value="N" name="checkbox" >N<br>
<input type="checkbox" value="O" name="checkbox" >O<br>
<input type="submit" value="Submit">
</form>

</body>
</html>
Nov 20 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3740
by: Frank Collins | last post by:
Can anyone point me to some good examples on the web of using values from dynamically created checkboxes on forms in ASP, particularly relating to INSERTING those values into a SQL or Access database? Basically, I have a form on which I have a series of statements, with 3 checkboxes for each statement - YES, NO, MAYBE. This series of statements is being dynamically populated from a query of a table in Access, called "tblQuestions". In...
1
1624
by: middletree | last post by:
Hate to post this in a separate post, but felt that the last thread was too far down to get noticed. It is called dynamic checkboxes, and it contained some good advice for me, but it led to another question, and I wanted to go ahead and post my question here in hopes of getting an answer. The advice given to me about having a number of checkboxes which are put onto the page from the database, was to name them all the same thing, and...
8
2833
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the boxes and saving to the database at the end with the 'Submit' command button. Is it possible to save the changes as the checkboxes are clicked? I suppose I'd need to write some dynamic ASP event handling at the same time as creating the checkboxes......
7
1952
by: pizzy | last post by:
PROBLEM: I CAN'T GET THE LAST RESUTS TO WORK CORRECTLY. I WOULD PROVIDE THE CODE (AND WILL IF REQUESTED). BUT IN MY OWN WORDS I AM TRYING TO HAVE THE FIRST FORM DYNAMICALLY CREATE INPUT BOXES BASED ON THE NUMBER ENTERED. THEN ON THE SECOND FORM (WHICH IS CREATED BY THE FIRST FORM CALLING A FUNCTION) I WANT THE USER TO BE ABLE TO CLICK ON ONE OF THE CHECKBOXES AND SEE MORE INPUT BOXES APPEAR. HAS ANYONE DONE SOMETHING LIKE THIS? IF SO,...
2
2449
by: trank | last post by:
I created some checkboxes(<input type=checkbox>) dynamically,and then I'd like to access these checkboxes in code behind using C#. For they are not standard controls like Windows Checkbox, I can't catch it by FindControl().....how can i do this? Many thanks a lot! By trank trank@dynamic-x.net
3
3986
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
3
5775
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the list generated, but now there are two problems I haven't been able to overcome: 1) ASP.Net is munging the checkbox ID/Names of the checkboxes: I give it a name like "myCheckbox" and asp.net is creating the checkboxes with the name...
34
3837
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript function needs to run and validate all the checkboxes on my form and make sure none of them are unchecked. I suck at Javascript and my problem is 2fold. I have the following code that constructs the checkbox response.write "<input type=checkbox...
1
4114
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem: I dynamically add an htmlcheckbox to a webform in the pages render and set the checked value to true. When the page loads, if I remove the check from the checkbox and then submit it, in the submit event the checkbox' checked value is still...
0
1518
by: TarekSaad | last post by:
I am using VB2005 and have created a dynamic list of checkboxes and depending on which file the user selects there may be between 1 and 20 checkboxed that appear in a form. The user then checks any number of these checkboxes. I know how many checkboxes exist. I want to scroll down through the check boxes, one after the other and depending on if they are checked or not I different things need to happen. How do I select checkbox 1,...
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.