Connecting Tech Pros Worldwide Help | Site Map

Check box and text box disable

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 11:23 AM
Jim
Guest
 
Posts: n/a
Default Check box and text box disable

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>

  #2  
Old July 23rd, 2005, 11:23 AM
Lee
Guest
 
Posts: n/a
Default Re: Check box and text box disable

Jim said:[color=blue]
>
>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[/color]

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>

  #3  
Old July 23rd, 2005, 11:23 AM
Dr John Stockton
Guest
 
Posts: n/a
Default Re: Check box and text box disable

JRS: In article <729757f9.0406031227.10a67aff@posting.google.com >, seen
in news:comp.lang.javascript, Jim <jim.ferris@motorola.com> posted at
Thu, 3 Jun 2004 13:27:04 :
[color=blue]
>function enableField()
>{
>if (chxrequest.checked)= true
>{
>document.frmcallreport.txtrequest.disabled= false;
>}
> if (chxrequest.checked)= false
> {
> document.frmcallreport.txtrequest.disabled= true;
>
> }
>
> }[/color]


(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.
  #4  
Old July 23rd, 2005, 11:24 AM
Randy Webb
Guest
 
Posts: n/a
Default Re: Check box and text box disable

Dr John Stockton wrote:
[color=blue]
> JRS: In article <729757f9.0406031227.10a67aff@posting.google.com >, seen
> in news:comp.lang.javascript, Jim <jim.ferris@motorola.com> posted at
> Thu, 3 Jun 2004 13:27:04 :
>
>[color=green]
>>function enableField()
>>{
>>if (chxrequest.checked)= true
>>{
>>document.frmcallreport.txtrequest.disabled= false;
>>}
>>if (chxrequest.checked)= false
>>{
>>document.frmcallreport.txtrequest.disabled= true;
>>
>>}
>>
>> }[/color]
>
>
>
> (a) In javascript, = is assignment, not comparison[/color]

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.
[color=blue]
> (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[/color]

But this is better:

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

the chxrequest.checked shortcut is an IE-ism.[color=blue]
> (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.[/color]

No comment.



--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.