473,750 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkboxs

Oli
Hi,

I have a form with a textbox...

<input type="text" name="textbox1" value="value1" disabled>

Obviously that produces a textbox that the user cannot edit.

What I want is when the user puts a tick in a checkbox next to the textbox
for the textbox to become active.

I know it's possible, but how?!

TIA
Oli
Jul 23 '05 #1
7 1283
On Sun, 17 Oct 2004 09:09:53 +0000 (UTC), Oli <ol*@NOSPAMoliw oods.co.uk>
wrote:
I have a form with a textbox...

<input type="text" name="textbox1" value="value1" disabled>
Might I suggest that you don't start with that HTML. If the user doesn't
have scripting enabled, the field will be completely useless. Instead,
disable the field once the page has loaded. In this case, if the user
agent cannot execute the script, the user can still enter a value. It's
then a matter of checking on the server that the checkbox is checked. If
it isn't, you might want to warn the user to make sure that's what they
didn't forget to check the box by accident.

Might I also suggest that you use better names for your elements;
"textbox1" isn't very informative.
Obviously that produces a textbox that the user cannot edit.

What I want is when the user puts a tick in a checkbox next to the
textbox for the textbox to become active.

I know it's possible, but how?!


function disable(elem, bool) {
elem.disabled = bool;
}

/* Disable the text box when the document loads. */
function initForm() {
disable(documen t.forms['myForm'].elements['textbox1'], true);
}

<body onload="initFor m();">

<!-- ... -->

<input type="checkbox"
onchange="disab le(this.form.el ements['textbox1'], !this.checked); ">
<input type="text" name="textbox1" >

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
There are a variety of ways to do it depending on browsers, but this is one
would work on most. For even further browser support, "this" could be
replaced by 'checkbox1' and then replace elm.checked. with
document.myForm .elements(elm). checked

<script language="javas cript" type="text/javascript">
function setTextbox(elm, tobox){
if(elm.checked)
document.myForm .elements(tobox ).disabled=fals e;
else
document.myForm .elements(tobox ).disabled=true ;
}
</script>
<form name="myForm" method="post" action="">
<input type="text" name="textfield 1" id="textfield1 " value="value1"
disabled="disab led" />
<input type="checkbox" name="checkbox1 " id="checkbox1" value="checkbox "
onclick="setTex tbox(this,'text field1')" />
</form>
John

"Oli" <ol*@NOSPAMoliw oods.co.uk> wrote in message
news:ck******** **@titan.btinte rnet.com...
Hi,

I have a form with a textbox...

<input type="text" name="textbox1" value="value1" disabled>

Obviously that produces a textbox that the user cannot edit.

What I want is when the user puts a tick in a checkbox next to the textbox
for the textbox to become active.

I know it's possible, but how?!

TIA
Oli

Jul 23 '05 #3
On Sun, 17 Oct 2004 10:45:05 -0500, johkar <no********@msn .com> wrote:

[snip]
document.myForm .elements(elm). checked
Subscripting collections with parentheses is a Microsoft-ism. Whilst some
browsers do support it, merely as a compatibility feature, others - most
notably Mozilla - won't. Instead, use square brackets, which is the
correct, standardised method.

A minor point: you could use the forms collection in addition to elements:

document.forms['myForm'].elements[elm].checked
<script language="javas cript" type="text/javascript">
The language attribute is deprecated, and the (required) type attribute
makes it redundant anyway. Remove it.
function setTextbox(elm, tobox){
if(elm.checked)
document.myForm .elements(tobox ).disabled=fals e;
else
document.myForm .elements(tobox ).disabled=true ;
Along with the previous comments, you could simplify that to:

document.forms['myForm'].elements[elm].disable = !elm.checked;
}
</script>
<form name="myForm" method="post" action="">
<input type="text" name="textfield 1" id="textfield1 " value="value1"
disabled="disab led" />
Two points here:

1) It's generally a bad idea to disable a control via HTML. It makes the
form unusable to a visitor with Javascript unavailable.
2) Unless you're writing XHTML, which I doubt, don't include the slash at
the end of the tag. It makes what would otherwise be valid documents,
invalid for no reason.
<input type="checkbox" name="checkbox1 " id="checkbox1"
value="checkbox " onclick="setTex tbox(this,'text field1')" />
</form>


[snip]

Finally, please don't top-post.

Mike

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

Two points here:

1) It's generally a bad idea to disable a control via HTML. It makes the
form unusable to a visitor with Javascript unavailable.
2) Unless you're writing XHTML, which I doubt, don't include the slash at
the end of the tag. It makes what would otherwise be valid documents,
invalid for no reason.
<input type="checkbox" name="checkbox1 " id="checkbox1"
value="checkbox " onclick="setTex tbox(this,'text field1')" />
</form>

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


Point taken on the brackets. Enlighten me once more. Ending slashes on
inputs and such ala XHTML would cause errors in which browsers? I wasn't
aware of any, though you seem to be the expert.

John
Jul 23 '05 #5
johkar wrote:
Michael Winter<snip>
2) Unless you're writing XHTML, which I doubt, don't include
the slash at the end of the tag. It makes what would otherwise
be valid documents, invalid for no reason.

<snip> Point taken on the brackets. Enlighten me once more. Ending
slashes on inputs and such ala XHTML would cause errors in which
browsers? I wasn't aware of any, though you seem to be the
expert.


They don't cause errors, they are errors. They force the browser to put
in extra work error-correcting them.

In SGML they have formal meaning, but it isn't a meaning that
corresponds with what you expect them to do, and HTML web browsers
disregard that formal meaning anyway and just treat them as errors.

Richard.
Jul 23 '05 #6
Re: Checkboxs
From: Richard Cornford
Date Posted: 10/17/2004 9:23:00 PM

johkar wrote:
Michael Winter<snip>
2) Unless you're writing XHTML, which I doubt, don't include
the slash at the end of the tag. It makes what would otherwise
be valid documents, invalid for no reason.

<snip> Point taken on the brackets. Enlighten me once more. Ending
slashes on inputs and such ala XHTML would cause errors in which
browsers? I wasn't aware of any, though you seem to be the
expert.


They don't cause errors, they are errors. They force the browser to put
in extra work error-correcting them.

In SGML they have formal meaning, but it isn't a meaning that
corresponds with what you expect them to do, and HTML web browsers
disregard that formal meaning anyway and just treat them as errors.

Richard.
Ok, I understand XHTML replaces HTML 4; and also understand most browsers
don't truly support it yet...or treat it like HTML if you leave off the
declaration. So assume they did, would you not use XHTML ever? I am just
trying to understand when to use it. Are all the experts behind the Web
Standards Project wrong? http://www.webstandards.org/

John
Jul 23 '05 #7
On Mon, 18 Oct 2004 05:52:46 -0500, johkar <no********@msn .com> wrote:
Re: Checkboxs
From: Richard Cornford
Date Posted: 10/17/2004 9:23:00 PM
At present it appears that either your news reader is broken, or you've
disabled normal quoting when replying. I'm not going to force the issue,
but it would be nice for you to reply properly, resulting in properly
threaded, and quoted, posts.

[snip]
Ok, I understand XHTML replaces HTML 4;
I don't know about "replaces". It is the next in line, but with IE
(unfortunately holding the largest market share) unable to properly
support XHTML, I fail to see the point of using it. As I understand it, it
will be impossible to have IE parse the page without invoking quirks-mode,
because the mark-up will be treated as malformed HTML.
and also understand most browsers don't truly support it yet
I was under that impression that modern browsers did, but they are
outnumbered by IE which doesn't.
...or treat it like HTML if you leave off the declaration.
More importantly, as I already said, they treat it as malformed HTML. That
seems to me to be a step backward.
So assume they did, would you not use XHTML ever?
"Not ever" is too strong, but I personally won't use it for quite a long
time. All browsers can handle Strict HTML, which is probably better for
the moment than Strict XHTML.
I am just trying to understand when to use it.
I couldn't honestly say when a good time to switch over would come. I
suppose it's like writing for browsers like NN4, now. Is it really worth
it? Some argue yes, others no. When (if) the same situation occurs with
XHTML - that the number of people that will use error-corrected HTML,
rather than XHTML, drops to a vast minority - then I'd consider using it.
Are all the experts behind the Web Standards Project wrong?
http://www.webstandards.org/


I think perhaps your interpretation is. From a quick look around, I see
nothing that says, "Abandon HTML! You must switch to XHTML or the Web is
doomed!"

The main aim of the organisation is to promote the use of Web-related
standards. HTML is just as big a part of those standards as any of the
other technologies and, if used properly, it will achieve the intended
goals just as well: forward compatibility, accessibility, and the
separation of presentation and content.

The important point is that you write semantically correct, valid mark-up,
and that you don't intentionally hinder the accessibility of your work. I
think the reason why XHTML is proclaimed as the way forward is that, in
theory, it enforces the former. However, that would only hold true if user
agents strictly conform to parsing rules, intentionally breaking
badly-written documents. From what I've read elsewhere, this isn't
happening meaning that malformed XHTML is likely to be published just like
HTML.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8

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

Similar topics

3
1709
by: Nik Coughin | last post by:
I am having a problem with checkboxes... I have a number of blocks like this on my form: <input type="text" name="name" value="a name"> <input type="text" name="ddi" value="1234"> <input type="checkbox" name="delete"> If I then submit the form, the array $delete is the only one which isn't indexed by its order on the form.
1
2790
by: John | last post by:
Where I can find sample code for adding checkboxs in a DataGrid? Thanks
2
1214
by: Iain Downie | last post by:
Dear List, I have a snippet of code below that creates a new input element for a checkbox and sets some attributes. var observationCheckbox = document.createElement('input'); observationCheckbox.setAttribute('type', 'checkbox'); observationCheckbox.setAttribute('id', 'observation.' + runningCount + '.species'); observationCheckbox.setAttribute('name', 'observation.' + runningCount +
5
12398
by: MS News | last post by:
Hello, how do I get an x-number of check boxes in a listbox is it possible what other contols that have a scrol bar can hold checkboxes inside them thanks
2
1064
by: JJ | last post by:
Hi, I have a group of checkboxs in the beginning of each row of a table. Each row has other controls in it. When I get a set of values back from the database and one of the values is of course what checkbox sould be checked. I am wondering how u guys would code the rest of the fields in the row to be databound. Now i'm not asking how u databind to a control, I know how to do this. I'm asking would u put your code in a select statement...
0
1010
by: TrevorHEK | last post by:
I am using c# and I made a Static DataGrid. I have my own function to set columns and template columns the way I want at runtime. I have been using the same grid class I made for many projects so far without a problem till now. In one page I have one column with a dropdown list. I change it in many rows and click update which generates update statements based on the grid. It works perfectly, I intergrate it to my fellow developers project...
1
991
by: diddi | last post by:
hi all is there an easy way of working with a number of checkboxes on a form so that, for eg, they can all be cleared or set quickly or, for eg clearing a group of labels or textboxes. thx for any ideas.
17
2710
by: shivasusan | last post by:
Hi! In my program, I have multiple check boxs.(more the 10) But i give rights to select 2 check boxs, If i select more then 2 check boxs, I want to display alert message. Please any one post me modle program. Please very very urgent.... any only help me... By Susan.
3
1591
by: kccced | last post by:
I have a form with a check box and a sub form that loads with the on load event when the sub form loads it checks to see if there is any records unchecked and returns the unchecked records but the sub form shows all records (How do I get just the unchecked to show ??) Email address removed per forum rules
0
9000
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
9396
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
9339
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
9256
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
8260
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
6804
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...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
2804
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.