javascript mind twister

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Sep 2007
Posts: 1,484
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

javascript mind twister

 
0
  #1
Apr 8th, 2009
I have being trying to make a javascript code that will show different submenus depending on what was selected on the previous menu. Although my script has no bugs according to Internet Explorer it seems to not work in IE nor Crome. Can anybody see what's wrong with this code because it looks perfect but just doesn't work as in won't display the submenus on selection.
  1. <head><script language=javascript type='text/javascript'>
  2. function showprojecttype(var1) {
  3. if (document.getElementById) { // DOM3 = IE5, NS6
  4. document.getElementById('divmodify').style.visibility = 'hidden';
  5. document.getElementById('divcreate').style.visibility = 'hidden';
  6. } else {
  7. if (document.layers) { // Netscape 4
  8. document.divmodify.visibility = 'hidden';
  9. document.divcreate.visibility = 'hidden';
  10. } else { // IE 4
  11. document.all.divmodify.style.visibility = 'hidden';
  12. document.all.divcreate.style.visibility = 'hidden';
  13. }
  14. }
  15.  
  16. if (var1=='divcreate') {
  17. if (document.getElementById) { // DOM3 = IE5, NS6
  18. document.getElementById('divcreate').style.visibility = 'visible';
  19. } else {
  20. if (document.layers) { // Netscape 4
  21. document.divcreate.visibility = 'visible';
  22. } else { // IE 4
  23. document.all.divcreate.style.visibility = 'visible';
  24. }
  25. }
  26. } else {
  27. if (document.getElementById) { // DOM3 = IE5, NS6
  28. document.getElementById('divmodify').style.visibility = 'visible';
  29. } else {
  30. if (document.layers) { // Netscape 4
  31. document.divmodify.visibility = 'visible';
  32. } else { // IE 4
  33. document.all.divmodify.style.visibility = 'visible';
  34. }
  35. }
  36. }
  37. }
  38. </script></head><body onload=javascript:showprojecttype('divcreate');>
  39. <form method='post' style='margin:0px; padding:0px;' name='form1'>
  40.  
  41. Modify or Create:<select name='modify||create' size=1 onchange='javascript:showprojecttype(this.options[this.selectedIndex].value);'>
  42. <option value='divcreate'>
  43. <option value='divcreate'>Create
  44. <option value='divmodify'>Modify
  45. </select><br>
  46. <select id='divmodify' name='divmodify' size=1 style='display:none;'>
  47. <option value='1'>option a
  48. <option value='1'>option b
  49. <option value='1'>option c
  50. <option value='1'>option d
  51. </select>
  52. <div id='divcreate' name='divcreate' style='display:none;'>
  53. If this text shows it probably works.
  54. </div>
  55. </form></body>
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - MacGyver Fan
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,484
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: javascript mind twister

 
0
  #2
Apr 8th, 2009
Silly me. I didn't follow the tutorial properly. I just found out that javascript was meant to hide the menus and not css. There for my fixed code is as follows and this topic is solved.
  1. <body>
  2. <form method='post' style='margin:0px; padding:0px;' name='form1'>
  3.  
  4. Modify or Create:<select name='modify||create' size=1 onchange='javascript:showprojecttype(this.options[this.selectedIndex].value);'>
  5. <option value=''>Select
  6. <option value='divcreate'>Create
  7. <option value='divmodify'>Modify
  8. </select><br>
  9. <select id='divmodify' name='divmodify' size=1>
  10. <option value='1'>option a
  11. <option value='1'>option b
  12. <option value='1'>option c
  13. <option value='1'>option d
  14. </select>
  15. <div id='divcreate' name='divcreate'>
  16. If this text shows it probably works.
  17. </div>
  18. </form>
  19. <script language=javascript type='text/javascript'>
  20. if (document.getElementById) { // DOM3 = IE5, NS6
  21. document.getElementById('divmodify').style.visibility = 'hidden';
  22. document.getElementById('divcreate').style.visibility = 'hidden';
  23. } else {
  24. if (document.layers) { // Netscape 4
  25. document.divmodify.visibility = 'hidden';
  26. document.divcreate.visibility = 'hidden';
  27. } else { // IE 4
  28. document.all.divmodify.style.visibility = 'hidden';
  29. document.all.divcreate.style.visibility = 'hidden';
  30. }
  31. }
  32. function showprojecttype(var1) {
  33. if (document.getElementById) { // DOM3 = IE5, NS6
  34. document.getElementById('divmodify').style.visibility = 'hidden';
  35. document.getElementById('divcreate').style.visibility = 'hidden';
  36. } else {
  37. if (document.layers) { // Netscape 4
  38. document.divmodify.visibility = 'hidden';
  39. document.divcreate.visibility = 'hidden';
  40. } else { // IE 4
  41. document.all.divmodify.style.visibility = 'hidden';
  42. document.all.divcreate.style.visibility = 'hidden';
  43. }
  44. }
  45.  
  46. if (var1=='divcreate') {
  47. if (document.getElementById) { // DOM3 = IE5, NS6
  48. document.getElementById('divcreate').style.visibility = 'visible';
  49. } else if (var1=='divmodify') {
  50. if (document.layers) { // Netscape 4
  51. document.divcreate.visibility = 'visible';
  52. } else { // IE 4
  53. document.all.divcreate.style.visibility = 'visible';
  54. }
  55. }
  56. } else {
  57. if (document.getElementById) { // DOM3 = IE5, NS6
  58. document.getElementById('divmodify').style.visibility = 'visible';
  59. } else {
  60. if (document.layers) { // Netscape 4
  61. document.divmodify.visibility = 'visible';
  62. } else { // IE 4
  63. document.all.divmodify.style.visibility = 'visible';
  64. }
  65. }
  66. }
  67. }
  68. </script></body>
*Solved*
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - MacGyver Fan
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC