473,396 Members | 1,671 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.

Checkbox

How can I, on button click, to select ONLY the following 4 checkbox?

I would like to do this without a for loop through form.lenght because
this is only an example and I have to apply this script on a 10k+ lines
page and IE, looping through a form with 20k+ elements is VERY SLOW.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
<input type="button" name="Submit" value="Select"
onclick="sel(next_four_elements);">
<input type="checkbox" name="1">
<input type="checkbox" name="2">
<input type="checkbox" name="3">
<input type="checkbox" name="4">
<br>
<br>
<input type="button" name="Submit" value="Select"
onclick="sel(next_four_elements);">
<input type="checkbox" name="5">
<input type="checkbox" name="6">
<input type="checkbox" name="7">
<input type="checkbox" name="8">
</form>
</body>
</html>
I was thinking about

<pseudo-code>

function sel(w){
/* select following 4 elements after you */
}

</pseudo-code>
Any help much appreciated.

Regards.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #1
4 2020
"Fabri" <no@sp.am> wrote in message news:32*************@individual.net...
How can I, on button click, to select ONLY the following 4 checkbox?

I would like to do this without a for loop through form.lenght because
this is only an example and I have to apply this script on a 10k+ lines
page and IE, looping through a form with 20k+ elements is VERY SLOW.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
<input type="button" name="Submit" value="Select"
onclick="sel(next_four_elements);">
<input type="checkbox" name="1">
<input type="checkbox" name="2">
<input type="checkbox" name="3">
<input type="checkbox" name="4">
<br>
<br>
<input type="button" name="Submit" value="Select"
onclick="sel(next_four_elements);">
<input type="checkbox" name="5">
<input type="checkbox" name="6">
<input type="checkbox" name="7">
<input type="checkbox" name="8">
</form>
</body>
</html>
I was thinking about

<pseudo-code>

function sel(w){
/* select following 4 elements after you */
}

</pseudo-code>
Any help much appreciated.

Regards.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))


Will this help? Watch for word-wrap.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function sel(beg,end) {
for (var i=beg; i<end+1; i++) {
document.getElementById(i).checked = true;
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="button" value="Select" onclick="sel(1,4);">
<input type="checkbox" name="1">
<input type="checkbox" name="2">
<input type="checkbox" name="3">
<input type="checkbox" name="4">
<br>
<br>
<input type="button" value="Select" onclick="sel(5,8);">
<input type="checkbox" name="5">
<input type="checkbox" name="6">
<input type="checkbox" name="7">
<input type="checkbox" name="8">
</form>
</body>
</html>

You probably don't want
name="Submit"
on all of the buttons!
Jul 23 '05 #2
On Fri, 17 Dec 2004 13:09:17 +0100, Fabri <no@sp.am> wrote:
How can I, on button click, to select ONLY the following 4 checkbox?


If you're only concerned with IE (5+) then

/* getNextElement(o, t)
*
* This moves from sibling node to sibling node trying to find
* elements. The returned elements can be restricted by name.
*
* Input:
* o - The position within the tree where the search will begin.
* This node will not be returned as a match.
* t - An optional string that specifies the name of an element
* type. Only these elements will be returned. If any element
* should be matched, either pass null or nothing at all.
*
* If no matching siblings are found, the return value is null.
*
* Note: If t is a string, it will be converted to uppercase before
* being compared to a node. That makes this particular
* version unsuitable for XML documents without modification.
*/
var getNextElement = (function() {
function isS(o) {return 'string' == typeof o;}
function isE(o, t) {var r;
if((r = (o.nodeType == 1))) {
if(isS(t)) {r = (o.nodeName == t);}
}
return r;
}
return function(o, t) {
if(!o) {return null;}
if(t) {t = String(t).toUpperCase();}
do {o = o.nextSibling;} while(o && !isE(o, t));
return o;
};
})();

function sel(node) {
for(var i = 0; (i < 4) && node; ++i, node = getNextElement(node)) {
node.checked = true;
}
}

called with

<input type="button" ... onclick="sel(this);">

will suffice. It will also work with other browsers, but it wouldn't be
quite so appropriate on the Web.

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Michael Winter wrote:
[snip]

Hope that helps,
Mike


Wow. :-)

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #4
JRS: In article <32*************@individual.net>, dated Fri, 17 Dec
2004 13:09:17, seen in news:comp.lang.javascript, Fabri <no@sp.am>
posted :
How can I, on button click, to select ONLY the following 4 checkbox?


This is like yours, but the boxes are renamed and sel() takes a
parameter :-

<form name="form1" method="post" action="">
<input type="button" name="Submit" value="Select"
onclick="sel('x');">
<input type="checkbox" name="x0">
<input type="checkbox" name="x1">
<input type="checkbox" name="x2">
<input type="checkbox" name="x3">
<br>
<br>
<input type="button" name="Submit" value="Select"
onclick="sel('y');">
<input type="checkbox" name="y0">
<input type="checkbox" name="y1">
<input type="checkbox" name="y2">
<input type="checkbox" name="y3">
</form>

<script>
function sel(z) { var j
for (j=0;j<4;j++) form1.elements[z+j].checked=true }
</script>

Works in IE4 (in my js-quick.htm, naturally); AFAIK, should work in
others.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: feanor | last post by:
I need to select children checkboxes when selecting the parent one. This is my function: function SelectChildrens(checkbox_name){ form = document.forms; Sname = checkbox_name.split("-"); for...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
2
by: bebop | last post by:
I'm using three checkbox web controls in C# .NET and one button, and one labe Is there a way to "group" these individual checkbox web controls If so, do I use a for loop, hashtable, array,...
5
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.......
2
by: Adam Knight | last post by:
Hi all, I have a datagrid with a checkbox in one column. The checkbox is set to autopostback and calls a method named UpdateMailSubscribers. The first click on the checkbox cause the page to...
2
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox...
4
by: Wolfgang Uhr | last post by:
Hello I've the following code Panel pnlData = new System.Windows.Forms.Panel(); CheckBox checkBox = new System.Windows.Forms.CheckBox(); checkBox.AutoSize = true; checkBox.Dock =...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
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.