Check box and text box disable

J

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>
 
L

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.checked"
value="ON"
style="float:left">

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

Dr John Stockton

JRS: In article <[email protected]>, seen
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.
 
R

Randy Webb

Dr said:
JRS: In article <[email protected]>, seen
in Jim <[email protected]> posted at
Thu, 3 Jun 2004 13:27:04 :





(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top