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

Javascript working in IE but not in Firefox

P: 89
Hello out there....

I have a javascript that goes like this:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function checkFields9(){        
  3.         if (shopform.totalhwtemp.value<=16) {
  4.             return true
  5.         }else{
  6.             shopform.hw.value = "0.00"
  7.             shopform.priceperpiece.value = "0.00"
  8.             shopform.subtotal.value = "0.00"
  9.             shopform.total.value = "0.00"
  10.             shopform.totalbund.value = "0.00"
  11.             document.getElementById("skjulpris").style.display = "block";
  12.             document.getElementById("vispris").style.display = "none";
  13.             document.getElementById("upload").style.display = "none";
  14.             alert("---IMPORTANT INFORMATION !---\n\n\The requested quantity is larger than 16 dm2 (1 production panel) and at the moment not available.\n\n\Please change quantity or direct this enquiry to sales@printline.dk or by phone + 45 66 10 74 60.\n\n\All quantities will soon be an option on our webshop.")                        
  15.             return false
  16.         }
  17.  
  18. }
  19. </script>
Can anyone tell me what could wrong...???

Thanks!
Oct 10 '08 #1
Share this Question
Share on Google+
7 Replies


gits
Expert Mod 5K+
P: 5,235
first you should drop the language attrib (which is deprecated) and use:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
next: what is not working? do you get an error? you should give your form-nodes ids and reference them with document.getElementById() too ...

kind regards
Oct 10 '08 #2

P: 44
For starters, you're missing all of your semi-colons.
Oct 11 '08 #3

Atli
Expert 5K+
P: 5,058
Where does the "shopform" variable come from?

Have you checked the Error Console in Firefox?
(Tools->Error Console.... or just CTRL+SHIFT+J)

For starters, you're missing all of your semi-colons.
Annoyingly, they aren't really necessary. Most browsers parse the code fine without them.

Although, I would highly recommend using them, if only to improve readability.
Oct 11 '08 #4

P: 89
Hello

Tried adding the semicolon's, no luck...

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function checkFields9(){        
  3.         if (shopform.totalhwtemp.value<=16) {
  4.             return true
  5.         }else{
  6.             shopform.hw.value = "0.00";
  7.             shopform.priceperpiece.value = "0.00";
  8.             shopform.subtotal.value = "0.00";
  9.             shopform.total.value = "0.00";
  10.             shopform.totalbund.value = "0.00";
  11.             document.getElementById("skjulpris").style.display = "block";
  12.             document.getElementById("vispris").style.display = "none";
  13.             document.getElementById("upload").style.display = "none";
  14.             alert("---IMPORTANT INFORMATION !---\n\n\The requested quantity is larger than 16 dm2 (1 production panel) and at the moment not available.\n\n\Please change quantity or direct this enquiry to sales@printline.dk or by phone + 45 66 10 74 60.\n\n\All quantities will soon be an option on our webshop.");                        
  15.             return false
  16.         }
  17.  
  18. }
  19. </script>
The sceneraio is as follows:

I have this field in a form:

[HTML]<input type="text" value="0.0" name="totalhwtemp" onblur="" size="3" style="background-color: transparent; border-style: solid; border-width: 0px 0px 0px 0px; border-color: darkred; text-align:right; font-family:Helvetica, sans-serif; font-size:11px; color:#000000;">[/HTML]

I do the check like this:

[HTML]<img src="../../images/beregn_de.jpg" id="beregn" border="0" onclick="checkFields9();checkFields3_1()" />[/HTML]

In IE the alert box comes up if the field totalhwtemp is above 16, but not in Firefox. Tried the error console in Firefox. I get an error saying that shopform is not defined and then the line "if (shopform.totalhwtemp.value<=16) {" is highlighted.

I believe my form is defined in the line that says:

[HTML]<form method="post" name="shopform" action="upload.php" onkeypress="return disableEnterKey(event)" id="shopform" onsubmit=""> [/HTML]
Oct 13 '08 #5

acoder
Expert Mod 15k+
P: 16,027
You can't access shopform globally like that. IE allows you to do so unfortunately.

Use document.getElementById("shopform") to access the form.
Oct 13 '08 #6

P: 89
Thanks, that did the trick.

But......

I do the same check in another place where it doen't work in Firefox, but it does in IE.

[HTML]<input name="pcbheight" id="beregnvis3" type="text" onkeypress="return disableEnterKey(event)" style="font-family:Helvetica, sans-serif; font-size:11px;" onblur="checkFields9()" value="" size="3" />[/HTML]

Could you perhaps tell me why....???

I tried putting the "checkFields9()" into an onchange event, and that works, but the check should be performed when leaving the field, not when changing it...
Oct 13 '08 #7

acoder
Expert Mod 15k+
P: 16,027
When you say it doesn't work, can you elaborate? Any errors? What happens instead?

Note that you shouldn't have alerts onblur - use some notification span/div instead.
Oct 13 '08 #8

Post your reply

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