473,394 Members | 1,932 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,394 software developers and data experts.

Hard Checkboxes Question

I am pretty new to using JavaScript for web applications. I need to
get some code that disables the input text box until the checkbox
beside is checked. Any examples of accomplishing this task?

Thanks.

Jul 23 '05 #1
5 1097
<li************@hotmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I am pretty new to using JavaScript for web applications. I need to
get some code that disables the input text box until the checkbox
beside is checked. Any examples of accomplishing this task?

Thanks.

Will this help? Watch for word-wrap.

<html>
<head>
<title>boxtext1.htm</title>
</head>
<body>
<form action="" method="post" name="form1">
<input type="checkbox" onclick="document.form1.data.disabled=false">
<input type="text" name="data" disabled></p>
</form>
</body>
</html>

Or this:

<html>
<head>
<title>boxtext2.htm</title>
<script type="text/javascript">
function enable() {
var form = document.form1;
form.data.disabled = false;
form.data.style.backgroundColor = "#FFFFFF";
form.data.focus();
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="checkbox" onclick="enable()">
<input type="text" name="data" disabled
style="background-color:#EEEEEE"></p>
</form>
</body>
</html>
Jul 23 '05 #2
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:Vo********************@comcast.com...

[snip]

Please ignore "</p>" in my prevous post.

Jul 23 '05 #3
On Sun, 23 Jan 2005 22:34:09 -0600, McKirahan <Ne**@McKirahan.com> wrote:

[snip]
<input type="text" name="data" disabled>


Disabling a form control in HTML will render it useless to anyone without
Javascript. The better approach is to disable the control with Javascript
- then you know the control can be enabled later.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Thanks for the replies. I think I am going to go with the 'or this:'
solution provided above. It seems to work with only minor tweaking to
handle the user checking and unchecking the box.
Thanks again. U guys are tooooo smart!

Jul 23 '05 #5
li************@hotmail.com wrote:
Thanks for the replies. I think I am going to go with the 'or this:'
solution provided above. It seems to work with only minor tweaking to handle the user checking and unchecking the box.
Thanks again. U guys are tooooo smart!


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>

<script type="text/javascript">

function initEnable()
{
function set_enable()
{
this.tbox.disabled = !this.checked;
this.tbox.select();
if (!this.checked)
this.tbox.value = this.tbox.defaultValue;
}

var f = document.forms, flen = f.length, el, els, j;
for (var i = 0; i < flen; ++i)
{
els = document.forms[i].elements;
j = 0;
for (; j < els.length; ++j)
{
el = els[j];
if (/\benable\b/.test(el.className))
{
el.tbox = els[++j];
el.onclick = set_enable;
el.onclick();
}
}
}
}

window.onload = initEnable;

</script>
</head>
<body>
<form style="width:180px;">
<input class="enable" type="checkbox" />:::<input type="text" name="t1"
value=" enter name" />
<input class="enable" type="checkbox" />:::<input type="text" name="t2"
value=" enter address" />
<input class="enable" type="checkbox" />:::<input type="text" name="t3"
value=" enter phone" />
<input class="enable" type="checkbox" />:::<input type="text" name="t4"
value=" enter email" />
<br />
<input type="checkbox" /><input type="text" name="t5" value="test" />
</form>
</body>
</html>

Jul 23 '05 #6

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

Similar topics

6
by: LRW | last post by:
I have no idea if this is more a PHP question or Javascript question, because my problem hinges equally on both. I have a PHP script that queries a database and creates a list of rows for each...
6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
5
by: Deborah V. Gardner | last post by:
I would like to use "Yes" and "No" checkboxes on a subform. The problem is that when I click the Yes checkbox on the subform, all of the checkboxes are checked. Currently, I have a field...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
2
by: SalamElias | last post by:
When creating checkboxes dynamically, I assign the ID property as follows : chkBox.ID ="myID", when runing the ASPX page I see a name attribute in the input *************************************...
1
by: MrHelpMe | last post by:
Hello experts, I need a hand. On my asp submit page I have the following code: for i = 1 to 5 ' 5 question form' Question = Request.Form("Q" & i) Answer = Request.Form("A" & i) Comment ...
19
by: Brian Kendig | last post by:
I want to have a set of nested UL elements where every LI has a checkbox associated with it, and the checkboxes are all lined up vertically either to the left or the right of the list. In other...
2
by: BillE | last post by:
Users of a VS2005 asp.net web forms application can complete questionnaires, and when they are completed the questionnaires can be viewed but not modified. Once completed, the controls in the...
14
by: zufie | last post by:
I have to create a QA report regarding callers calling into a phone hotline. The report consists of many checkboxes such as: Did the IBCCP agency contact you? Yes/NO How many days passed...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.