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

Hide/Show input field based on a value of drop down list

Hi,
I need to to hide a field"addr_state1" based on a value in the drop down list field called "addr_country".i.e.,if addr_country.value=="in" then hide addr_state1 else , and if the value in the selection changes to something else then show the field addr_state1. Also the addr_state1 should be hidden when the page loads with value "IN", and if the page loads some other value than show the addr_state1 field.
Code used for this is :(I have to add this code to an CRM software. where i have to hide the field conditionally)

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. window.attachEvent("onload",hidefield); 
  3. window.attachEvent("onchange",hidefield1);
  4. function hidefield()
  5. {
  6. if(document.getElementById("addr_country").value=='IN')
  7. {
  8. document.getElementById("addr_state1").style.visibility=hidden;
  9. }
  10. }
  11.  
  12. function hidefield1()
  13. {
  14. if(document.getElementById("addr_country").value!='IN')
  15. {
  16. document.getElementById("addr_state1").style.visibility=visible;
  17. }
  18. else 
  19. {
  20. document.getElementById("addr_state1").style.visibility=hidden;
  21. }
  22. </script>
Please hlp me!!!!!!!
Mar 17 '08 #1
1 4922
acoder
16,027 Expert Mod 8TB
attachEvent is a non-standard IE-only method. Unless this is for an IE-only application, you should also use window.addEventListener.

The onchange should be attached to the drop-down list, not to the window.
Mar 17 '08 #2

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

Similar topics

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...
9
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
4
by: riteshjain82 | last post by:
Hi, I am maintaining a site which is written in ASP. Now i have to create some new pages. In one page we have a table with many rows. Now, I want to enable or disable(showing and hiding also) 2...
2
Chittaranjan
by: Chittaranjan | last post by:
Hi All, I am having a problem using Javascript in Perl script. In the perl module I have included the Javascript codes and that is workign fine for validation purpose but when I am trying to show...
4
by: coldfusionstudent | last post by:
i wish to show/appear and dissappear text box based on a the drop down item selected. what do i have to add? thanks under Comm_DEV drop down selection.
1
by: TechnoAtif | last post by:
HI.. I am looking for php code that will enable me to hide/show a text box based on the users previous drop down list response. If javascript comes into use for it, its a welcome solution (1)...
1
by: yasminussain | last post by:
Hi to all, I have written one jsp file. In that file, I have one drop down which contains list of request name (like student name) based on the selected value within drop down I will display the...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.