Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 12-17-2008, 07:12 AM
Junior Member
 
Join Date: 12-17-08
Posts: 1
iTrader: 0 / 0%
Javascript Function Not Working

I have a Javascript function to display a different <form> each time a drop down box is clicked. All forms are set to display: none but when one of the options in the drop down box is clicked, one appears. If another is clicked, the current one appearing disappears and the new one appears. It works fine in Firefox but not in Internet Explorer 6 or 7 and I don't know why. My code is as follows:

Code:
function showm(ob,ob2,ob3) { document.getElementById(ob).style.display = 'block' document.getElementById(ob2).style.display = 'none' document.getElementById(ob3).style.display = 'none' }
HTML Code:
<form id="form1" name="form1" method="post" action=""> <select name="changer" id="changer"> <option value="" selected="selected">Please select your delivery area</option> <option value="SWD S09 UK" onclick="showm('swd_s09_uk','swd_s09_eu','swd_s09_rw')">United Kingdom</option> <option value="SWD S09 EU" onclick="showm('swd_s09_eu','swd_s09_uk','swd_s09_rw')">Europe</option> <option value="SWD S09 RW" onclick="showm('swd_s09_rw','swd_s09_uk','swd_s09_eu')">Rest of World</option> </select> </form> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_uk" style="display:none;"> Paypal button </form> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_eu" style="display:none;"> Paypal button </form> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_rw" style="display:none;"> Paypal button </form>
 
Reply With Quote
  #2 (permalink)  
Old 12-17-2008, 07:51 AM
kos's Avatar
kos kos is offline
Coding Tiger
Latest Blog:
Happy New Year 2013

 
Join Date: 04-13-07
Location: .ro
Posts: 4,030
iTrader: 3 / 100%
tested in both IE7 & FF 3 (I don't have IE6 but I find no reason why it shouldn't work in it too)

Code:
<body> <form id="form1" name="form1" method="post" action=""> <select name="changer" id="changer" onchange="handleOnChange(this, 'swd_s09_uk','swd_s09_eu','swd_s09_rw');"> <option value="" selected="selected">Please select your delivery area</option> <option id="uk" value="SWD S09 UK">United Kingdom</option> <option id="eu" value="SWD S09 EU">Europe</option> <option id="rw" value="SWD S09 RW">Rest of World</option> </select> </form> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_uk" style="display:none;"> Paypal button </form> <!-- * UK --> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_eu" style="display:none;"> Paypal button </form> <!-- * EU --> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_rw" style="display:none;"> Paypal button </form> <!-- * RW --> <script type="text/javascript"> function showm() { document.getElementById(arguments[0]).style.display = 'block'; document.getElementById(arguments[1]).style.display = document.getElementById(arguments[2]).style.display = 'none'; } function handleOnChange(selectCtl,ob,ob2,ob3) { var index = selectCtl.options[selectCtl.selectedIndex]; if (index.getAttribute('id') == 'uk') { return showm(ob,ob2,ob3); } else if (index.getAttribute('id') == 'eu') { return showm(ob2,ob,ob3); } else if (index.getAttribute('id') == 'rw') { return showm(ob3,ob2,ob); } else { return null; } } </script> </body>
I've changed your code a little bit.
 
Reply With Quote
  #3 (permalink)  
Old 12-18-2008, 09:51 AM
Contributing Member
Latest Blog:
None

 
Join Date: 11-17-08
Location: NJ
Posts: 55
iTrader: 0 / 0%
I suspect that your code doesn't work in IE because it doesn't fire onclick from option

try to add this: option value="SWD S09 UK" onclick="alert(this); show......

and see what happens.
__________________
Leonid
 
Reply With Quote
  #4 (permalink)  
Old 12-18-2008, 10:05 AM
Contributing Member
Latest Blog:
None

 
Join Date: 11-17-08
Location: NJ
Posts: 55
iTrader: 0 / 0%
Here is my version (works in IE7 and FF3).
I used prototype.js library, so it is compact and low maintanance.

Code:
<script type="text/javascript" src="../javascript/prototype.js"></script> <script type="text/javascript"> function showm(select){ var keep = $A(select.options)[select.selectedIndex]; var fArr = $$("form.pp"); fArr.each( function(el){ el.style.display = 'none'; } ); ($('swd_s09_'+keep.id)).style.display='block'; }//end showm </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <select name="changer" id="changer" onchange="showm(this);" > <option value="" selected="selected">Please select your delivery area</option> <option id="uk" value="SWD S09 UK">United Kingdom</option> <option id="eu" value="SWD S09 EU">Europe</option> <option id="rw" value="SWD S09 RW">Rest of World</option> </select> </form> <form class="pp" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_uk" style="display:none;"> Paypal button UK </form> <form class="pp" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_eu" style="display:none;"> Paypal button EU </form> <form class="pp" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="swd_s09_rw" style="display:none;"> Paypal button RW </form
__________________
Leonid
 
Reply With Quote
  #5 (permalink)  
Old 12-19-2008, 04:10 AM
kos's Avatar
kos kos is offline
Coding Tiger
Latest Blog:
Happy New Year 2013

 
Join Date: 04-13-07
Location: .ro
Posts: 4,030
iTrader: 3 / 100%
^^ you'd load a full library for something trivial like this?? wow..
 
Reply With Quote
  #6 (permalink)  
Old 12-19-2008, 10:55 AM
Contributing Member
Latest Blog:
None

 
Join Date: 11-17-08
Location: NJ
Posts: 55
iTrader: 0 / 0%
When a user interacts with a web site and a javascript library (e.g. prototype.js) is mentioned on multiple pages, it'll be loaded only once.

prototype.js is a very useful library and greatly simplifies your code.

BTW, if I want now to add more options (for example, I can divide "The rest of the world" into "Asia", "North America", etc), I don't have to recode -- only HTML needs to
change.
__________________
Leonid
 
Reply With Quote
  #7 (permalink)  
Old 12-19-2008, 02:30 PM
kos's Avatar
kos kos is offline
Coding Tiger
Latest Blog:
Happy New Year 2013

 
Join Date: 04-13-07
Location: .ro
Posts: 4,030
iTrader: 3 / 100%
Quote:
Originally Posted by leonid View Post
When a user interacts with a web site and a javascript library (e.g. prototype.js) is mentioned on multiple pages, it'll be loaded only once.
nope. the library will be loaded everytime the page is requested (unless other factors are involved: like caching)


Quote:
Originally Posted by leonid View Post
prototype.js is a very useful library and greatly simplifies your code.
definitely. But in his case I doubt that he's using prototype.
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript not working in FF only IE CircleOfLinks Coding Forum 4 05-18-2008 02:36 PM
JavaScript - Function is undefined (But I defined it, I swear!) pipelineae Coding Forum 1 03-09-2008 07:16 AM
Cannot assign a function to JavaScript event; o_O. stewart Coding Forum 3 11-22-2007 10:07 AM
Simple javascript popup window not working in FF spyderscripts Coding Forum 2 07-15-2006 07:02 PM
Two HTML similar codes , one working well and another not working why? Banjika Web Design Lobby 1 06-11-2005 07:14 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 05:33 AM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.