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

Javascript not working in firefox ??

onlymars
P: 13
here the code of a currency convertor i am using in my page which is not working in firefox but works in internet explorer.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.     function convert()
  3.     {
  4.     var to, from;
  5.     var to_rate, from_rate;
  6.     var quantity, result;
  7.     var temp;
  8.  
  9.     to=window.f1.select2.selectedIndex;
  10.     to_rate=window.f1.select2.options[to].value;
  11.  
  12.     from=window.f1.select1.selectedIndex;
  13.     from_rate=window.f1.select1.options[from].value;
  14.  
  15.     quantity=window.f1.amount.value;
  16.  
  17.     if(quantity=="")
  18.     {
  19.     window.alert("Plz specify any amount");
  20.     window.f1.amount.focus();
  21.     }
  22.     else if(to==from)
  23.     {
  24.     alert("Please select different currencies");
  25.     }
  26.     else 
  27.     {
  28.     temp=quantity/to_rate;
  29.     result=temp*from_rate;
  30.     window.f1.result.value=result;
  31.     }
  32.     }
  33. </script>
  34.  
you can also visite the page at www.malikexchange.com
Apr 8 '08 #1
Share this Question
Share on Google+
7 Replies


gits
Expert Mod 5K+
P: 5,390
use w3c-compliant dom-methods for ALL the references to document-nodes ... for example:

Expand|Select|Wrap|Line Numbers
  1. var my_form = document.getElementsByName('f1')[0];
when you use that methods in nearly most cases you will not have any issues regarding such referencing problems between browsers ...

kind regards
Apr 8 '08 #2

onlymars
P: 13
Thanx i visited the DOM objects and methods but i didn't understood a thing in it, can u plz just edit my code to work properly. ur support will be really appreciated.
Apr 9 '08 #3

kunal pawar
100+
P: 297
i suppose, this will help you
<script language="javascript" type="text/javascript">
Expand|Select|Wrap|Line Numbers
  1.     function convert()
  2.     {
  3.     var to, from;
  4.     var to_rate, from_rate;
  5.     var quantity, result;
  6.     var temp;
  7.  
  8.         to=document.getElementById("select2").selectedIndex;
  9.     to_rate=document.getElementById("select2").options[to].value;
  10.  
  11.     from=document.getElementById("select1").selectedIndex;
  12.     from_rate=document.getElementById("select1").options[from].value;
  13.  
  14.     quantity=document.getElementById("amount").value;
  15.  
  16.     if(quantity=="")
  17.     {
  18.       alert("Plz specify any amount");
  19.       document.getElementByID("amount").focus();
  20.     }
  21.     else if(to==from)
  22.     {
  23.     alert("Please select different currencies");
  24.     }
  25.     else 
  26.     {
  27.     temp=quantity/to_rate;
  28.     result=temp*from_rate;
  29.     document.getElementByID("result").value=result;
  30.     }
  31.     }
</script>
Apr 9 '08 #4

acoder
Expert Mod 15k+
P: 16,027
kunal, as a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).

This makes it easier for everyone to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

MODERATOR.
Apr 9 '08 #5

acoder
Expert Mod 15k+
P: 16,027
here the code of a currency convertor i am using in my page which is not working in firefox but works in internet explorer.
Replacing window.f1 with document.f1 might be enough.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.     function convert()
  3.     {
  4.     var to, from;
  5.     var to_rate, from_rate;
  6.     var quantity, result;
  7.     var temp;
  8.  
  9.     to=document.f1.select2.selectedIndex;
  10.     to_rate=document.f1.select2.options[to].value;
  11.  
  12.     from=document.f1.select1.selectedIndex;
  13.     from_rate=document.f1.select1.options[from].value;
  14.  
  15.     quantity=document.f1.amount.value;
  16.  
  17.     if(quantity=="")
  18.     {
  19.     window.alert("Plz specify any amount");
  20.     document..f1.amount.focus();
  21.     }
  22.     else if(to==from)
  23.     {
  24.     alert("Please select different currencies");
  25.     }
  26.     else 
  27.     {
  28.     temp=quantity/to_rate;
  29.     result=temp*from_rate;
  30.     document.f1.result.value=result;
  31.     }
  32.     }
  33. </script>
  34.  
Apr 9 '08 #6

kunal pawar
100+
P: 297
sorry, i will take care next time
Apr 11 '08 #7

acoder
Expert Mod 15k+
P: 16,027
sorry, i will take care next time
Thanks !
Apr 11 '08 #8

Post your reply

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