473,795 Members | 3,151 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ruby check_boxes - check all/uncheck all with Javascript

I have the three embedded Ruby(erb) check_boxes below:

Patient #1<%= check_box("pati ent", '1', {}, "yes","no") %></br>
Patient #2<%= check_box("pati ent", '2', {}, "yes","no") %></br>
Patient #4<%= check_box("pati ent", '4', {}, "yes","no") %></br>
The HTML output looks like this:

Patient #1<input id="patient_1" name="patient[1]" type="checkbox"
value="yes" /><input name="patient[1]" type="hidden" value="no" /></br>

Patient #2<input id="patient_2" name="patient[2]" type="checkbox"
value="yes" /><input name="patient[2]" type="hidden" value="no" /></br>

Patient #4<input id="patient_4" name="patient[4]" type="checkbox"
value="yes" /><input name="patient[4]" type="hidden" value="no" /></br>
I want to create a button(s) to check all/uncheck all the check_boxes
if clicked by the user. I was thinking I had to use javascript to do
this, but the erb is appending the value to the name in the HTML
output. What this does is prevent my javascript from recognizing these
check_boxes as a collection named "patient".

I know this isn't a pure javascript question, but I am at a loss. I am
new to both languages, which doesn't help either.

Thank you for your time!

-Hunter

Apr 25 '06 #1
1 2761
wa**********@gm ail.com wrote:
I have the three embedded Ruby(erb) check_boxes below:

Patient #1<%= check_box("pati ent", '1', {}, "yes","no") %></br>
Patient #2<%= check_box("pati ent", '2', {}, "yes","no") %></br>
Patient #4<%= check_box("pati ent", '4', {}, "yes","no") %></br>
I think you need to remove one of yes or no. I don't know why you would
want the hidden input below.
The HTML output looks like this:

Patient #1<input id="patient_1" name="patient[1]" type="checkbox"
value="yes" /><input name="patient[1]" type="hidden" value="no" /></br>

Patient #2<input id="patient_2" name="patient[2]" type="checkbox"
value="yes" /><input name="patient[2]" type="hidden" value="no" /></br>

Patient #4<input id="patient_4" name="patient[4]" type="checkbox"
value="yes" /><input name="patient[4]" type="hidden" value="no" /></br>


I think the following is close to what you want. If you are using
prototype.js in your rails app I have read that it breaks the
javascript for-in loop although I haven't experienced this breakage
even when using prototype.js.

I am not so sure that my regular expressions are the best possible
option but they seem to work here.

The "return false;" makes it so the button calls the checkAll()
function but afterwards does not actually submit the form to the
specified form action.

- Peter
<html>
<head>

<script type="text/javascript">
function checkAll(form, list){
for (property in form) {
if(property.mat ch(new RegExp(list+"\\[\\d*?\\]"))){
form[property].checked = true;
}
}
}

function uncheckAll(form , list){
for (property in form) {
if(property.mat ch(new RegExp(list+"\\[\\d*?\\]"))){
form[property].checked = false;
}
}
}

</script>

</head>
<body>

<form name="myform" action="destina tion">
Patient #1<input id="patient_1" name="patient[1]" type="checkbox"
value="yes" /></br>
Patient #2<input id="patient_2" name="patient[2]" type="checkbox"
value="yes" /></br>
Patient #4<input id="patient_4" name="patient[4]" type="checkbox"
value="yes" /></br>
<button onclick='checkA ll(document.myf orm, "patient");retu rn
false;'>Check All</button>
<button onclick='unchec kAll(document.m yform, "patient");retu rn
false;'>Uncheck All</button>
<input type="submit" value="submit the form" />
</form>

</body>

</html>

Apr 25 '06 #2

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

Similar topics

2
3235
by: Askari | last post by:
Hi, How do for do a "select()" on a CheckButton in a menu (make with add_checkbutton(....) )? I can modify title, state, etc but not the "check state". :-( Askari
13
2712
by: Wayne Folta | last post by:
I've been a long-time Perl programmer, though I've not used a boatload of packages nor much of the tacky OO. A couple of years ago, I decided to look into Python and Ruby. Python looked OK, but not that different. I did like the indent-as-group idea, which was different. Ruby looked very cool. But it was impossible to get good documentation. It seemed like a Japanese cult with a few western initiates. Well, MacOS X ships with Perl,...
10
2288
by: Neal | last post by:
I'm beginning some experiments with Ruby in XHTML 1.1. I'm finding very odd results which surprise me. I'm using a PHP snippet which serves application/xml+xhtml and XHTML 1.1 to those browsers which accept it, and text/html XHTML 1.0 otherwise. I included a simple Ruby setup, first without using the <rp> elements, then with. My results? O7.23 does not render simple Ruby with the overtext as described in the spec, but does not display...
10
5209
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. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
5
2812
by: kid | last post by:
Hi, I have 5 checkbox elements, i.e: ( 1 ) a ( 2 ) b ( 3 ) c ( 4 ) d ( Check/Uncheck all )
12
4055
by: swebster | last post by:
I need to zero in on a specific section of my jsp form during a hide to uncheck the checkboxes in that section. Currently, anything I try either unchecks all checkboxes on the form or doesn't work at all. When I associated the specific section with ID the first box within the div is unchecked but not the second. Suggestions? <div id="menu1" class=hide> <div id="col1"> <input type="checkbox" name="Topic" value="_topic1"...
23
2797
by: kigoobe | last post by:
Hi friends, I'm having a menu like this - http://www.kigoobe.com/offshoring/bugs/javascript/treeMenuCheckToggle.gif that I've fetched from the database, using recursive function, where data is stored as - id | title | parent I need a javascript function, that will help me to check / uncheck child elements (if present) when I click on a parent at different level.
13
3096
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the checkboxes (code pasted below). But if name of the checkbox array is 'chkbx_ary' then it's failing. I want the name to be 'chkbx_ary' because I want to access this array at server side. Though one may not require to see php part but I'm still pasting...
1
5187
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the checkboxes (code pasted below). But if name of the checkbox array is 'chkbx_ary' then it's failing. I want the name to be 'chkbx_ary' because I want to access this array at server side. Though one may not require to see php part but I'm still pasting...
0
9672
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
9519
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
10214
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
10164
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,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
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...
1
4113
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
3727
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.