By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

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

P: 3
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. }
  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
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
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

Post your reply

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