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

Check box and text box disable

Jim
I have a text box and a check box, by default the page should load and
the text box be disabled..I want it so that when you click the check
box the text box diabled = false...but, when you uncheck the check box
I want the disabled to = true again..heres what I have so far

<input type="checkbox" name="chxrequest"
onclick="javascript:enableField()" value="ON" style="float: "left" >
<script language="javascript">

function enableField()
{
if (chxrequest.checked)= true
{
document.frmcallreport.txtrequest.disabled= false;
}
if (chxrequest.checked)= false
{
document.frmcallreport.txtrequest.disabled= true;

}

} </script>

<input type = "text" id="txtrequest" name="txtrequest" size="20"
disabled></td>
Jul 23 '05 #1
3 9988
Lee
Jim said:

I have a text box and a check box, by default the page should load and
the text box be disabled..I want it so that when you click the check
box the text box diabled = false...but, when you uncheck the check box
I want the disabled to = true again


You want the disabled attribute of txtrequest to have the
opposite boolean value of the checked attribute of chxrequest:

<input type="checkbox"
name="chxrequest"
onclick="this.form.txtrequest.disabled=!this.check ed"
value="ON"
style="float:left">

<input type="text"
id="txtrequest"
name="txtrequest"
size="20"
disabled>

Jul 23 '05 #2
JRS: In article <72**************************@posting.google.com >, seen
in news:comp.lang.javascript, Jim <ji********@motorola.com> posted at
Thu, 3 Jun 2004 13:27:04 :
function enableField()
{
if (chxrequest.checked)= true
{
document.frmcallreport.txtrequest.disabled= false;
}
if (chxrequest.checked)= false
{
document.frmcallreport.txtrequest.disabled= true;

}

}

(a) In javascript, = is assignment, not comparison
(b) It is almost never desirable to compare with true or false
(c) For the body of the function, this is simpler :
document.frmcallreport.txtrequest.disabled = ! chxrequest.checked
(d) The function would be more general / more expressive with chxrequest
as a parameter
(e) ISTM that you need a better instructor, or a more competently-
written book; for the latter, see the newsgroup FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3
Dr John Stockton wrote:
JRS: In article <72**************************@posting.google.com >, seen
in news:comp.lang.javascript, Jim <ji********@motorola.com> posted at
Thu, 3 Jun 2004 13:27:04 :

function enableField()
{
if (chxrequest.checked)= true
{
document.frmcallreport.txtrequest.disabled= false;
}
if (chxrequest.checked)= false
{
document.frmcallreport.txtrequest.disabled= true;

}

}
(a) In javascript, = is assignment, not comparison


That depends, directly on the browser and how the script tag is
constructed. In Netscape 4.xx with language="javascript1.2", then the =
does indeed do a comparison.
(b) It is almost never desirable to compare with true or false
(c) For the body of the function, this is simpler :
document.frmcallreport.txtrequest.disabled = ! chxrequest.checked
But this is better:

document.frmcallreport.txtrequest.disabled =
!document.frmcallreport.chxrequest.checked

the chxrequest.checked shortcut is an IE-ism. (d) The function would be more general / more expressive with chxrequest
as a parameter
(e) ISTM that you need a better instructor, or a more competently-
written book; for the latter, see the newsgroup FAQ.


No comment.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #4

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

Similar topics

6
by: Tony Roost | last post by:
I have created a test VB.Net form that will use MS Word to check the spelling of text in an input box The test application runs without a problem and I quit the word application at the end of the...
9
by: simonmarkjones | last post by:
I want to call a function which does this when the next record button is pressed (calling it from before update) if textboxes are empty then Message box you must fill text box
4
by: Jon | last post by:
Hi, I used XslCompiledTransform with the following Xsl file. The <xsl:text disable-output-escaping="yes"does not work when using XslCompiledTransform to do the trnasform (namely the output...
8
by: cptuser | last post by:
Hi, I've put together this javascript taken from various sources, but i think it is wrong or missing something. If particular options are selected within a drop down menu, then the check botton...
3
by: AJHY | last post by:
Hi Just a quick one. I have a form with a checkbox and 3 different text boxes on (Hidden). When a user clicks on the checkbox I want the first text box to be visable. This is fine but the...
8
by: Cirene | last post by:
I have an asp.net label on my webform. (The webform is based on a master page.) Using javascript how do I check the text value of the ASP.NET label? The label is called lblCar. Thanks!
1
by: Paul Ginsherman | last post by:
I need the following to check if the user entered the word: (the following is a snippet of the full scritp) 'Verifies repairStatus is one of valid status. if repairStatus<>ucase("new") AND...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.