HighDots Forums  

Re: Help selecting multiple checkboxes based on partial value

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Help selecting multiple checkboxes based on partial value in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JL
 
Posts: n/a

Default Re: Help selecting multiple checkboxes based on partial value - 03-09-2008 , 04:27 PM






Thanks!
This looks like it works for all checkboxes within the form. That
means the buttons also have to be within the form. If the buttons
were not placed within the form, is there some way to make the onclick
action check all checkboxes on the entire page?

Reply With Quote
  #2  
Old   
JL
 
Posts: n/a

Default Re: Help selecting multiple checkboxes based on partial value - 03-09-2008 , 05:18 PM






I see now.

I did discover 1 small problem when i adjusted the code to change the
buttons to check boxes.

<script type="text/javascript">
function f(frm, val) {
var len = frm.elements.length;
for (var i=0;i<len;i++) {
if (('checked' in frm.elements[i]) &&
(frm.elements[i].value.indexOf(val,0) != -1)) {
frm.elements[i].checked = !frm.elements[i].checked;
}
}
}
</script>


<INPUT onclick="f(this.form, '1##')" type=checkbox
name=CheckOnlySlipHeaders> <b>
<font face="Arial" style="font-size: 11px" color="#666644">
Select All Billing Slip Headers</font></b>

<INPUT onclick="f(this.form, '81#')" type=checkbox
name=CheckOnlyPatReg> <b>
<font face="Arial" style="font-size: 11px" color="#666644">
Select All Patient Registration Forms</font></b>



The first checkbox that is supposed to select any box starting with
the value 1## is actually checking any box containing 1##. So it
selects more boxes that it is supposed to.

For example it selects:
21##
61##
81##

But it does not select:
22##
23##
Because the do not contain 1##.

Is there a way to change this from 'containing' to 'starting with' ?

Reply With Quote
  #3  
Old   
JL
 
Posts: n/a

Default Re: Help selecting multiple checkboxes based on partial value - 03-09-2008 , 06:18 PM



I think i fixed it...

I changed
frm.elements[i].value.indexOf(val,0) != -1))
to
frm.elements[i].value.indexOf(val,0) == 0))

I will test fully on Monday when i am in the office and see if i need
more tweaking.

Thanks for the help so far!

Reply With Quote
  #4  
Old   
VK
 
Posts: n/a

Default Re: Help selecting multiple checkboxes based on partial value - 03-09-2008 , 06:24 PM



On Mar 10, 1:18 am, JL <justin.la... (AT) gmail (DOT) com> wrote:
Quote:
I think i fixed it...

I changed
frm.elements[i].value.indexOf(val,0) != -1))
to
frm.elements[i].value.indexOf(val,0) == 0))
Right! And sorry, that is what I meant to type:

frm.elements[i].value.indexOf(val) == 0

so the 0 in argument is not needed; sometimes you think one things but
your fingers are typing what they used to ( == -1 is the most
casual). :-)

It also can be made as a RegExp check, I just wanted to keep things as
simple as possible, so used indexOf instead.


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.