简体   繁体   中英

Javascript not Firing in Chrome and Safari

I have some javascript that won't fire in Chrome and Safari but works fine in Firefox and IE. I cannot seem to figure out what the problem is. I tried removing the OnClick event handler from the options and changing it to an OnChange in the Select, but that did not work either. Not sure if it is just a matter of a slight syntax difference that I am omiting for Chrome and Safari or what it is:

<script type="text/javascript">

var year = new Date();
var year1 =year.getFullYear() -1;
var year2 =year.getFullYear() -2;
var year3 =year.getFullYear() -3;
var year4 =year.getFullYear() -4;
var year9 =year.getFullYear() -9;
</script>

<script>


//When called, this finds the parameter that you pass to it
function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

//This calls the above function to find the guid, then it redirects the page
function getGuidAndGo(a)
{  

//Get the Guid
var myGuid = getUrlVars()["guid"];

switch(a)
{
case 1:
window.location = "https://dev-arenaweb.gocf.org/ContrReport_selectyr_internal.aspx?negnum=1&guid=" + myGuid;
break;

case 2:
window.location = "https://dev-arenaweb.gocf.org/ContrReport_selectyr_internal.aspx?negnum=2&guid=" + myGuid;
break;

case 3:
window.location = "https://dev-arenaweb.gocf.org/ContrReport_selectyr_internal.aspx?negnum=3&guid=" + myGuid;
break;
}

} 

</script>

    <head>
    <body>
        <div id="mainbg">
        <span style="font-weight: bold; font-size: 18px;">Contribution Statement</span>
        <span style="font-size: 16px;"><br />
        </span>
        <span style="font-size: 16px;">Please select a year for the Contribution Statement that you would like to view.</span>
        <br />
        <em>(A .pdf will be generated. May take a few seconds to load...)</em> <br />
        <br />
        <br />
        <select>
        <option value="#">Select a Year</option>
        <option id="myYear1" onClick="getGuidAndGo(1)" value="">
<script type="text/javascript">document.write(year1);</script>
        </option>
        <option id="yYear2" onClick="getGuidAndGo(2)" value="">
<script type="text/javascript">document.write(year2);</script>
        </option>
        <option id="myYear3" onClick="getGuidAndGo(3)" value="">
<script type="text/javascript">document.write(year3);</script>
        </option>
        </select>

Chrome does not support the onclick event on option-tags. Use the onchange event on the select-tag instead.

See here: javascript onclick alert not working in chrome

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM