简体   繁体   中英

Javascript not loading on one page, works fine on another

I have the following piece of javascript on one of my pages

<script type="text/javascript">
var state = 'none';
function showhide(layer_ref, badgeid, location) {
    alert("Run")
    if (state == 'block') {
        state = 'none';
    }
    else
    {
        state = 'block';
    }

    hza = document.getElementById(layer_ref);
    hza.style.display = state;

    if (state == 'block') {
        badgeinfo(badgeid, location);
    }
}
</script>

its called using

<td width="50%" align="right" valign="middle" onclick="showhide('id215', '215', 'req_215');"><img src="/images/badges/2015be-cs-csa.png" width="100" height="100" alt="Chief Scout's Bronze Award" /></td>

One on page its loads fine, i get the alert when i click the image, but on another page, nothing happens, the alert isn't shown.

The page is dynamically produced based on a couple of variables which define what section is loaded. Even if i change the javascript function to just the alert it doesn't do anything. If i change the section of the badges in the database so they load on another page its fine, and previously working badges if they are on this section don't load

This is the non working page http://new.wgcscouts.co.uk/test1.php

And this is a working one http://new.wgcscouts.co.uk/test2.php

In the working example, there is an index number appended to the section url...

url=url+"&amp;section="+1;

The number at the end of line 51 is not being populated in the non-working example

url=url+"&amp;section="+;

That is a syntax error for javascript, which then stops executing as it can't parse the input.

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