Javascript working in IE but not in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • printline
    New Member
    • Jul 2006
    • 89

    Javascript working in IE but not in Firefox

    Hello out there....

    I have a javascript that goes like this:

    Code:
    <script language="javascript">
    function checkFields9(){        
            if (shopform.totalhwtemp.value<=16) {
                return true
            }else{
    		    shopform.hw.value = "0.00"
    			shopform.priceperpiece.value = "0.00"
    			shopform.subtotal.value = "0.00"
    			shopform.total.value = "0.00"
    			shopform.totalbund.value = "0.00"
    			document.getElementById("skjulpris").style.display = "block";
    			document.getElementById("vispris").style.display = "none";
    			document.getElementById("upload").style.display = "none";
                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.")						
                return false
            }
    
    }
    </script>
    Can anyone tell me what could wrong...???

    Thanks!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    first you should drop the language attrib (which is deprecated) and use:

    Code:
    <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.getEle mentById() too ...

    kind regards

    Comment

    • labmonkey111
      New Member
      • Sep 2008
      • 44

      #3
      For starters, you're missing all of your semi-colons.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Where does the "shopform" variable come from?

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

        Originally posted by labmonkey111
        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.

        Comment

        • printline
          New Member
          • Jul 2006
          • 89

          #5
          Hello

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

          Code:
          <script type="text/javascript"> 
          function checkFields9(){        
                  if (shopform.totalhwtemp.value<=16) {
                      return true
                  }else{
          		    shopform.hw.value = "0.00";
          			shopform.priceperpiece.value = "0.00";
          			shopform.subtotal.value = "0.00";
          			shopform.total.value = "0.00";
          			shopform.totalbund.value = "0.00";
          			document.getElementById("skjulpris").style.display = "block";
          			document.getElementById("vispris").style.display = "none";
          			document.getElementById("upload").style.display = "none";
                      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.");						
                      return false
                  }
          
          }
          </script>
          The sceneraio is as follows:

          I have this field in a form:

          [HTML]<input type="text" value="0.0" name="totalhwte mp" onblur="" size="3" style="backgrou nd-color: transparent; border-style: solid; border-width: 0px 0px 0px 0px; border-color: darkred; text-align:right; font-family:Helvetic a, 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="checkF ields9();checkF ields3_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.total hwtemp.value<=1 6) {" is highlighted.

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

          [HTML]<form method="post" name="shopform" action="upload. php" onkeypress="ret urn disableEnterKey (event)" id="shopform" onsubmit=""> [/HTML]

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You can't access shopform globally like that. IE allows you to do so unfortunately.

            Use document.getEle mentById("shopf orm") to access the form.

            Comment

            • printline
              New Member
              • Jul 2006
              • 89

              #7
              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="ret urn disableEnterKey (event)" style="font-family:Helvetic a, sans-serif; font-size:11px;" onblur="checkFi elds9()" 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...

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                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.

                Comment

                Working...