0

I have a simple page put together and it works great in IE, and Safari, but Firefox refuses to run the scripts... Can anyone pinpoint why? (Firefox v 3.6.19)

The Script File

// JavaScript Document
function spacesToPluses () {
    var resu = myform2.input3.value.replace (/\W/g, '\+');

    myform2.input4.value = resu;
}
function joinFieldsWithSpaces () {
    var first = myform2.inputbox.value;
    var second = myform2.input2.value;
    var third = first+" "+second;

    myform2.input3.value = third;

}

// GeoCoding Script


  var geocoder;
  var map;
  function initialize() {

    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(29.994638, -95.488186);
    var myOptions = {
      zoom: 10,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

  }


  function codeAddress() {

    var sAddress = document.getElementById("inputTextAddress").value;
    var lon;
    var lat;
    var splittingPoint;
    var stoppingPoint;

    geocoder.geocode( { 'address': sAddress}, function(results, status) {

        if (status == google.maps.GeocoderStatus.OK) {

            myform.numberLoc.value = results[0].geometry.location;
                alert(myform.numberLoc.value);

                if (myform.numberLoc.value.indexOf(",")!=-1){
                  alert(myform.numberLoc.value.indexOf(","))
                  splittingPoint = myform.numberLoc.value.indexOf(",");
                }
                if (myform.numberLoc.value.indexOf(")")!=-1){
                  alert(myform.numberLoc.value.indexOf(")"))
                  stoppingPoint = myform.numberLoc.value.indexOf(")");
                }

                lat = myform.numberLoc.value.substring(1, splittingPoint);
                lon = myform.numberLoc.value.substring(splittingPoint+2, stoppingPoint);

                myform.myLat.value = lat;
                myform.myLon.value = lon;


        } else {

            alert("Geocode was not successful for the following reason: " + status);
        }
      });
  }

The HTML file I'm using is here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex/nofollow" />

<title>Test Input</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript"src="StringScripts.js"></script>
</head>
<body onload="initialize()">
<h1>String Manipulation</h1>
<form action="" method="get" name="myform2" id="myform2">Enter something in the box: <br />
<input type="text" name="inputbox" value="" /><br /><br />
<input type="text" name="input2" value="" /><br /><br />

<input type="button" name="button" value="Combine Field 1 and 2" onclick="joinFieldsWithSpaces()" /><br /><br />
<input type="text" name="input3" value="" /><br /><br />

<input type="button" name="button" value="Click to add Plus Signs to Box 3" onclick="spacesToPluses()" />
<br /><br />
<input type="text" name="input4" value="" /><br /><br />
</form>
<hr />
<br />
<h1>Geocoding</h1>


<form name="myform" id="myform">

        <!--Create a text box input for the user to enter the street address-->
        Address: <input type="text" id="inputTextAddress" style=" width:200px" title="Address to Geocode"/>

        <!--Create a button input for the user to click to geocode the address-->
        <input type="button" onclick="codeAddress()" id="inputButtonGeocode" style="width:150px" title="Click to Geocode" value="Click to Geocode" /><br /><br />


        Latitude, Longitude: <input type="text" name="numberLoc" style=" width:200px" id="numberLoc" value="nothing entered yet"  /><br /><br />


        &nbsp;&nbsp;&nbsp;Latitude: <input type="text" name="myLat" style="width:125px" id="myLat" value="Null"  /><br />

        Longitude: <input type="text" name="myLon" style="width:125px" id="myLon" value="Null"  />


        </form>
</body>
</html>​

Any help would be greatly appreciated. I have never run into this problem before. I checked FF and I have JavaScript enabled, I don't have anything blocked, no plugins that would interfere with it.

I really am confused here, and I'm sure it's going to be one tiny thing I'm missing and will kick myself for not knowing.

4

1 回答 1

0

好的,我发现出了什么问题。显然 Firefox 要求您首先从文档中处理表单(例如,document.myform2.inputbox.value) 我错过了“文档”。

将其插入列表中,现在可以使用。

于 2012-08-09T18:15:20.177 回答