473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkbox to enable / disable hidden fields?

Hello.

I have a search form for music albums which among other things I need to
search all the song titles of the song. Normally in a search form I would
have checkboxes the user can use to select whether or not to search a given
field.

In this case it is not practical to have 20 checkboxes (each album can have
up to 20 song titles).

What I would rather do is have a single checkbox labeled "search song
titles" and have all the song title fields hidden and either enabled or
disabled as part of the search depending on the checked state of that check
box.

The hidden fields in question look like this:

<input type="hidden" name="SearchAdd _1" value="1">
<input type="hidden" name="SearchAdd _2" value="1">
etc
etc
all the way to
<input type="hidden" name="SearchAdd _20" value="1">

So if I simply put all those in the search form then it will search those
fields. Great. But how would I give the user the option to toggle them
off or on in one shot?

Thanks.
Sep 10 '05 #1
8 4260

If the fields are 'hidden', there isn't much point on disabling them,
unless you wish them disabled for them not to send along, which disabled
fields do, you can do quite a few on an event like in this case, onclick on
a checkbox, but you need to be specific on what you want, but is rather
quite simple to do using a For loop.
Danny
Sep 10 '05 #2
Sorry, should have been more specific. Yes, what I mean is I want them all
to not get sent along in the form. So effectively I need them to change
from:

<input type="hidden" name="SearchAdd _1" value="1">

to

<input type="hidden" name="SearchAdd _1" value="0">

If a checkbox is unchecked, and back to 1 if it is checked.

da*******@blueb ottle.com (Danny) wrote in
<1126325189.df9 99db5e087b893cb bc22d75bbbf24e@ teranews>:

If the fields are 'hidden', there isn't much point on disabling
them,
unless you wish them disabled for them not to send along, which disabled
fields do, you can do quite a few on an event like in this case, onclick
on a checkbox, but you need to be specific on what you want, but is
rather quite simple to do using a For loop.
Danny


Sep 10 '05 #3
John wrote:
I have a search form for music albums which among other things I need to
search all the song titles of the song. Normally in a search form I would
have checkboxes the user can use to select whether or not to search a
given field.

In this case it is not practical to have 20 checkboxes (each album can
have up to 20 song titles).


I'd do this on the server:

Pseudo code:

if (defined $album_to_searc h) {
push @songs_to_searc h, get_list_of_son g_ids_from_albu mid($album_to_s earch);
}

Much more reliable, and it doesn't require you to shunt all the song names
to the client each time.

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 10 '05 #4
ASM
John wrote:
Sorry, should have been more specific. Yes, what I mean is I want them all
to not get sent along in the form. So effectively I need them to change
from:

<input type="hidden" name="SearchAdd _1" value="1">

to

<input type="hidden" name="SearchAdd _1" value="0">

If a checkbox is unchecked, and back to 1 if it is checked.


<input type=checkbox onclick="Search Add_1.value= this.checked? 1 : 0;">

or to get true / false as value of SearchAdd_1 :

<input type=checkbox onclick="Search Add_1.value= this.checked;">
--
Stephane Moriaux et son [moins] vieux Mac
Sep 10 '05 #5
ASM wrote:
<input type="hidden" name="SearchAdd _1" value="0">

If a checkbox is unchecked, and back to 1 if it is checked.


<input type=checkbox onclick="Search Add_1.value= this.checked? 1 : 0;">


Most browsers don't automatically create, for each element with a name, a
variable with that name as a reference to that element.

onclick="this.f orm.elements['SearchAdd_1'].value ...

I still wouldn't use JavaScript to solve this problem though.

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 10 '05 #6
ASM
John wrote:
Sorry, should have been more specific. Yes, what I mean is I want them all
to not get sent along in the form. So effectively I need them to change
from:

<input type="hidden" name="SearchAdd _1" value="1">

to

<input type="hidden" name="SearchAdd _1" value="0">

If a checkbox is unchecked, and back to 1 if it is checked.


function checkSongs(myFo rm,val) {
var f = myForm;
val = val? 1 : 0 ;
for(var i=0;i<f.legnth; i++)
if(f[i].name.indexOf(' SearchAdd')==0) f[i].value = val;
}

Check or uncheck all :
<input type=checkbox onclick="checkS ongs(this.form, this.checked)">

Uncheck all :
<input type=button onclick="checkS ongs(this.form, false)" value=GO>
----------== other way ==--------

<form name="songsForm ".... blah ....>
<p>Pre-selection :
all <input type=radio name="presel" onclick="wichSo ngs()">
some <input type=radio name="presel" onclick="wichSo ngs()">
any <input type=radio name="presel" onclick="wichSo ngs()">
<p class=sg><input type=checkbox name="SearchAdd _1" value="0"> Title 1
<p class=sg><input type=checkbox name="SearchAdd _2" value="0"> Title 2
<p class=sg><input type=checkbox name="SearchAdd _3" value="0"> Title 3
....
<p class=sg><input type=checkbox name="SearchAdd _20" value="0"> Title 20

function whichSongs() {
var f = document.songsF orm;
var r = f.presel;
var j = 0;
for(var i=0;i<r.length; i++) if(r[i].checked) j=i;
var p = f.getElementsBy TagName('P');
for(var i=1;i<p.length; i++) {
if(p[i].className=='sg ') {
p[i].getElementsByT agName('INPUT')[0].checked=false;
p[i].getElementsByT agName('INPUT')[0].value=0;
if(j==2) p[i].style.display= 'none';
else p[i].style.display= '';
if(j==0) {
p[i].getElementsByT agName('INPUT')[0].checked=true;
p[i].getElementsByT agName('INPUT')[0].value=1;
}
}
}
}

--
Stephane Moriaux et son [moins] vieux Mac
Sep 10 '05 #7
ASM
David Dorward wrote:
ASM wrote:

<input type="hidden" name="SearchAdd _1" value="0">
[...]
I still wouldn't use JavaScript to solve this problem though.


Yeap, but here we speak about JS
and I understood question was about JS :)

anyway JS is only an help an can't be used to do server's job.

--
Stephane Moriaux et son [moins] vieux Mac
Sep 10 '05 #8
ASM wrote:
David Dorward wrote:

<snip>
<input type="hidden" name="SearchAdd _1" value="0">

[...]
I still wouldn't use JavaScript to solve this problem though.


Yeap, but here we speak about JS
and I understood question was about JS :)

<snip>

We may speak about JS here, but one of the things we are allowed to say
is that JS in an inappropriate technology for some tasks. I cannot see
anyone with a good understanding of server-side scripting (and
particularly the handling of form input with it, but that is probably
the first aspect of server-side scripting that anyone would learn) even
considering this. You just observe the state of the checkbox when the
request arrives at the server and act accordingly.

Richard.
Sep 11 '05 #9

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

Similar topics

0
2228
by: jwsacksteder | last post by:
I want to have a check box that can optionally disable a text input field in the same dialog. I am asking the user to input the start and end of a range and there needs to be a check box to select all items. When the checkbox changes state, I want to ghost-out the input fields. A rough approximation of the situation follows. class...
1
3496
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ? <li>ABACAVIR SULFATE</li> <INPUT NAME="ingredient0" TYPE=checkbox VALUE="ABACAVIR SULFATE"><br> <input name="ABACAVIR SULFATE AMOUNT" type="radio"...
6
3418
by: ML.Steve | last post by:
Hi, There are lots of posts on this subject but after a couple of hours of going though them I still can't get a number of fields to be disabled when a checkbox is ticked. Basically I have a lot of Forecast and Actual dates that can be entered, and next to each one an 'NA' checkbox that I want to disable/grey-out both dates (and the...
2
3777
by: Kufre | last post by:
I need anyone that have done this before to help me. I'm creating a form in Access, in the form has two two checkbox, checkbox A is paid, checkbox B is partial_paid. I want the set the checkbox so that if the user click on checkbox A which is Paid, then checkbox B which is partial_paid should be disable, visa versa, then if checkbox A which...
5
6689
by: fred | last post by:
hiya, I have got a checkbox in one of my cells in the ediit item template. Now i need to enable/disable a textbox in another boundcolumn. the problem i am facing is the checkchanged event is not raised or for some reason, the control does not enter the function. I have made the function as protected and specified the function name in...
4
10404
by: Matrixreloadedth | last post by:
How to change disable color of Checkbox??? I have a checkbox with forecolor in red but when i disable by set Enable properties to false forecolor is changed to gray color but i don't want it. how to make disable color as the same before set enable = false Anyone can help me?????
6
23834
by: tshad | last post by:
I am trying to disable and enable a checkbox from javascript. The problem is that if the checkbox starts out as: <input id="Override" type="checkbox" name="Override"/> I can change it back and forth with no problems. using disabled = true or disabled = false If I start out as:
2
26321
by: Kevin | last post by:
I've been looking all over and I can't seem to find what ought to be simple. I need to disable a drop down when a checkbox is checked, and enable it when same checkbox is unchecked. I've found any number of scripts to disable / enable a drop down but they are all made to work with 2 different buttons, radio group selections, etc. I can't...
7
2535
by: Srikanth Ram | last post by:
Hi, I'm creating a PHP application. In this a dynamic table with the fields in the database is generated in a page. I have placed a checkbox in each row of the table to approve/disapprove according to spec. This checkbox is also created dynamically according to the fields in the database. Now I need to place a checkbox/ button (by checking the...
0
7693
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...
0
7604
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...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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...
0
7962
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...
0
6275
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...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.