Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2005, 11:29 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enable & Disable a field using Javascript

Hello All
Environment : Progress Webspeed / HTML and JavaScript.

When the user press a button on page 1, I come to page 2 and render the page. The focus is on a hidden field on Page 2. There are 2 input box, one image for SEARCH and one button for CLEAR. The user has the option to click on any one of the following objects in the page. When the user clicks on the first input box, I want to disable input to the second input box unless otherwise, the user clicks on the CLEAR button again.

I do not want to remove the input box from the screen but would like to disable it so the user cannot type anything once they have typed something in the first field.

Any help will be greatly appreciated. Please help. If you need to talk to me, please feel free to call me or email me. I can be reached at 763-553-5458.

Thanks
Laxmi


 
Old January 24th, 2005, 02:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can set/unset either the DISABLED or the READONLY attribute of your textbox, or oyu could use some Javascript in an ONFOCUS event to detect whether or not to allows access to the field.
 
Old January 24th, 2005, 05:02 PM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Greg for giving me some insight. But I still seems to have problems and I am a rookie when it comes to Javascript.

Any help is greatly appreciated.


Here is more information. I have the code snippet from my .html and the other program where I use the Javascript function.

<TR>
    <TD ALIGN=right COLSTART=1>Unit Serial #:</TD>
    <TD COLSTART=2>
      <INPUT TYPE=text SIZE=25 maxlength=25 NAME="w_serial" onBlur="chkSerial()" value=''>
    </TD>
  </TR>
  <TR>
    <TD ALIGN=right COLSTART=1>Original Order #:</TD>
    <TD COLSTART=2>
      <INPUT TYPE=text SIZE=25 maxlength=25 NAME="w_gonumber" value='' >
    </TD>
    <TD COLSTART=3>
    <!--</TD> <These are in se210200.w>
  </TR>

{&OUT}
       "<SCRIPT LANGUAGE='JavaScript'>" SKIP
       " function chkSerial() ~{" SKIP
       " alert('Comes here ON Blur');" SKIP
       " if (document.forms[0].w_serial.value != '') ~{" SKIP
       " alert(document.forms[0].w_serial.value);" SKIP
       " document.forms[0].w_gonumber.visibility = 'HIDE';" SKIP
       " ~}" SKIP
       " ~}" SKIP
        " </SCRIPT>" SKIP
     {&END}


The field that I am trying to disable for input is shown below.

"document.forms[0].w_gonumber.visibility = 'HIDE'"

I am not sure whether this is correct. I want the field to be visible but not accept any input.

I am trying to accomplish this using JavaScript.

Please help.
Thanks
Laxmi
 
Old January 24th, 2005, 05:17 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please use
"document.forms[0].w_gonumber.disabled=true"
instead of
"document.forms[0].w_gonumber.visibility = 'HIDE'"

Om Prakash
 
Old January 24th, 2005, 07:27 PM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all your help. I have couple more request.

1. How do I disable a Radio button.

I have the following code in my program which renders the field for the Radio button.

<TR><TD ALIGN=RIGHT>Apply Warranty Info to all Line Items:&nbsp</TD>
<TD>
  <INPUT TYPE=radio NAME="w_apply_all" VALUE="YES" CHECKED>YES &nbsp;&nbsp;&nbsp;
  <INPUT TYPE=radio NAME="w_apply_all" VALUE="NO" >NO </TD>
</TR>

I have the following JavaScript with which I am trying to disable the Radio button and I am unsuccessful.

{&OUT}
"<SCRIPT LANGUAGE='JavaScript'>" SKIP
" function chkSerial() ~{" SKIP
" if (document.forms[1].w_apply_all.checked = 'TRUE') ~{" SKIP
" alert(document.forms[1].w_apply_all.checked);" SKIP
" document.forms[1].w_apply_all.disabled = 'TRUE';" SKIP
" ~}" SKIP
" document.forms[1].w_comments.disabled = 'TRUE';" SKIP
" document.forms[1].w_button.disabled = 'TRUE';" SKIP
" ~}" SKIP
" ~}" SKIP
" </SCRIPT>" SKIP
{&END}

Any help will be greatly appreciated. Thanks again for all those who have helped me so far.

Laxmi



 
Old January 24th, 2005, 07:53 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

i am not sure about the language used, but please replace the code after this line and check:
" function chkSerial() ~{" SKIP
----------------------------------------------
if (document.forms[1].w_apply_all.checked == true) ~{" SKIP
" alert(document.forms[1].w_apply_all.checked);" SKIP
" document.forms[1].w_apply_all.disabled = true;" SKIP
" ~}" SKIP
" document.forms[1].w_comments.disabled = true;" SKIP
" document.forms[1].w_button.disabled = true;" SKIP


Om Prakash
 
Old January 24th, 2005, 08:26 PM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help Om Prakash. It worked. I greatly appreciate your fast response.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using JS to enable/disable?? crabjoe Javascript 4 November 10th, 2008 06:48 PM
custom Property Enable & Disable in user control tiks C# 1 August 20th, 2008 09:31 AM
Disable and Enable at runtime Hammam ASP.NET 1.0 and 1.1 Professional 0 May 17th, 2006 12:40 AM
Disable/Enable elements ldoodle Javascript How-To 3 June 7th, 2005 05:48 AM
Enable/Disable Java,JavaScript,ActivX in WebBrower BunnyFace Pro VB 6 0 November 23rd, 2004 03:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.