Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Check box and text box disable

Reply
Thread Tools

Check box and text box disable

 
 
Jim
Guest
Posts: n/a
 
      06-03-2004
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>
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      06-03-2004
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>

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      06-04-2004
JRS: In article <(E-Mail Removed) >, seen
in news:comp.lang.javascript, Jim <(E-Mail Removed)> 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.
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      06-04-2004
Dr John Stockton wrote:

> JRS: In article <(E-Mail Removed) >, seen
> in news:comp.lang.javascript, Jim <(E-Mail Removed)> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
how to selecet check box in the data grid ?? only one check box mit ASP .Net 1 01-25-2006 06:47 PM
check box enable/disable vncntj@hotmail.com Javascript 1 01-03-2005 04:24 AM
check box enable/disable vncntj@hotmail.com Javascript 1 12-27-2004 10:14 AM
Disable a text box & still allow scrolling? harry HTML 5 08-01-2004 07:55 PM



Advertisments