473,396 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

dynamic checkboxes

Hello!

I need help to modify the following javascript:

[HTML]<script language="javascript">

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.length;i++) {
val += (fld.form.elements[flds[i]].checked)?vals[i]:0;
}
document.getElementById ('msg').innerHTML = msgs[val];

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

<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 4552
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="#FFFFFF">

<script Language="JavaScript">
<!--
function checkbox_checker()
{

// set var checkbox_choices to zero

var checkbox_choices = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_form.checkbox.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_choices = checkbox_choices + 1; }

}


if (checkbox_choices > 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_choices + " selections.\n"
msg=msg + "Please remove " + (checkbox_choices-3) + " selection(s)."
alert(msg)
return (false);
}


if (checkbox_choices < 3 )
{
// If there were less then selections made display an alert box
alert("Please make three selections. \n" + checkbox_choices + " 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="return checkbox_checker()" 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
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...
1
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...
8
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...
7
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...
2
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...
3
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...
3
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...
34
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...
1
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:...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.