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

Need to hide a form field (test) based on a previous field (select)

40
I have a form in which a select field lists 5 items pus the option of "Other." I want a text field to be hidden unless the select field value is "Other."

The form is HTML, but I am assuming that I need to accomplish this with Javascript. Sample HTML code follows for the select field and the following text field.

Expand|Select|Wrap|Line Numbers
  1. <td>Location:<br><select name="room_descr" size="1">
  2. <option value="">Select a Location</option>
  3. <option value="Patient Room">Patient Room</option>
  4. <option value="Therapy Gym">Therapy Gym</option>
  5. <option value="Cafeteria">Cafeteria</option>
  6. <option value="Hospital Grounds">Hospital Grounds</option>
  7. <option value="Hospital Contractor Site">Hospital Contractor Site</option>
  8. <option value="Other">Other</option>
  9. </select></td>
  10. <td>Other:<br><INPUT TYPE=TEXT NAME="oth_descr" SIZE=32 MAXLENGTH=25></td>
  11.  
I'm pretty new to HTML and to Javascript. I'd appreciate either an answer from this forum or some links to samples/reference books.

Thanks,

jej1216
May 24 '07 #1
3 1850
epots9
1,351 Expert 1GB
I have a form in which a select field lists 5 items pus the option of "Other." I want a text field to be hidden unless the select field value is "Other."

The form is HTML, but I am assuming that I need to accomplish this with Javascript. Sample HTML code follows for the select field and the following text field.

Expand|Select|Wrap|Line Numbers
  1. <td>Location:<br><select name="room_descr" size="1">
  2. <option value="">Select a Location</option>
  3. <option value="Patient Room">Patient Room</option>
  4. <option value="Therapy Gym">Therapy Gym</option>
  5. <option value="Cafeteria">Cafeteria</option>
  6. <option value="Hospital Grounds">Hospital Grounds</option>
  7. <option value="Hospital Contractor Site">Hospital Contractor Site</option>
  8. <option value="Other">Other</option>
  9. </select></td>
  10. <td>Other:<br><INPUT TYPE=TEXT NAME="oth_descr" SIZE=32 MAXLENGTH=25></td>
  11.  
I'm pretty new to HTML and to Javascript. I'd appreciate either an answer from this forum or some links to samples/reference books.

Thanks,

jej1216
[html]
<td>Other:<br><INPUT TYPE=TEXT NAME="oth_descr" SIZE=32 MAXLENGTH=25 disabled>
[/html]
and in your javascript
Expand|Select|Wrap|Line Numbers
  1. document.oth_descr.disabled = false
  2.  
if its in a form then
Expand|Select|Wrap|Line Numbers
  1. document.myForm.oth_descr.disabled = false
  2.  
thats should do the trick
May 24 '07 #2
jej1216
40
[html]
<td>Other:<br><INPUT TYPE=TEXT NAME="oth_descr" SIZE=32 MAXLENGTH=25 disabled>
[/html]
and in your javascript
Expand|Select|Wrap|Line Numbers
  1. document.oth_descr.disabled = false
  2.  
if its in a form then
Expand|Select|Wrap|Line Numbers
  1. document.myForm.oth_descr.disabled = false
  2.  
thats should do the trick
Thanks, epots9 - I understand where you set the text field to disabled and then override that with Javascript. Where do I put the Javascript? It needs to be following the "Other" option in the previous field, right?

I tried this but got errors:
Expand|Select|Wrap|Line Numbers
  1. <td>Location:<br><select name="room_descr" size="1">
  2. <option value="">Select a Location</option>
  3. <option value="Patient Room">Patient Room</option>
  4. <option value="Therapy Gym">Therapy Gym</option>
  5. <option value="Cafeteria">Cafeteria</option>
  6. <option value="Hospital Grounds">Hospital Grounds</option>
  7. <option value="Hospital Contractor Site">Hospital Contractor Site</option>
  8. <option value="Other">Other (Describe)
  9. <script language="JavaScript">
  10.     document.irform.oth_descr.disabled = false;
  11. </script></option>
  12. </select></td>
  13. <td>Other:<br><INPUT TYPE=TEXT NAME="oth_descr" SIZE=32 MAXLENGTH=25 disabled></td>
  14.  
The form name is irform.

Thanks,
jej1216
May 24 '07 #3
epots9
1,351 Expert 1GB
put the javascript in the header

<script type="text/javascript">
function whatever()
{
//if option other is selected, enable textbox code
}
</script>

in the <select> tag add the attribute: [html]onchange="whatever();"[/html]
May 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
6
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
9
by: Susan Bricker | last post by:
Greetings. I am having trouble populating text data that represents data in my table. Here's the setup: There is a People Table (name, address, phone, ...) peopleID = autonumber key There...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
3
by: steveninfl | last post by:
Hello , I am using MS Access 2000. I have a Table called Transactions, I have created a form for this table, one of the fields on the form is a combo box with the row source type as value list. In...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.