Variable_Name is not defined error, but actually is defined

时间:2016-04-04 18:57:05

标签: javascript joomla

I'm using RSForm to create a booking engine that passes the user submitted form data to a hotel's booking engine. Something changed somewhere, and now the form doesn't work. When I click "Check Rates" after selecting my check in and out, and number of adults and children, Firebug returns this error and nothing else happens:

ReferenceError: be_link is not defined http://vistacayholidays.com/ Line 195

This is the JavaScript:

<script>
function postIHForm(oForm){
    var qs = "";

    qs = qs + "?hotelid=" + document.getElementById("HotelID").value;
    if (oForm.LanguageID) { qs = qs + "&languageid=" + oForm.LanguageID.value}
    qs = qs + "&datein=" + document.getElementById("txtcal5_0").value;
    if (document.getElementById("Length")) { qs = qs + "&length=" + document.getElementById("Length").value }
    if (document.getElementById("txtcal5_1")) { qs = qs + "&dateout=" + document.getElementById("txtcal5_1").value }
    qs = qs + "&Adults=" + document.getElementById("Adults").value;
    if (document.getElementById("Children")) { qs = qs + "&children=" + document.getElementById("Children").value }
        var target = 'https://booking.ihotelier.com/istay/istay.jsp' + qs;
        ga(function(tracker) {
            var linker = new window.gaplugins.Linker(tracker);
            var be_link = linker.decorate(target);
        });
        window.open(be_link);
}
</script>

As far as I can tell, everything should be working. Here is a pastebin of the home page to view the tracking code: http://pastebin.com/x0vcmMds

I've tried taking out the be_link lines and still nothing happens, but I don't get an error either. I know absolutely no JavaScript and am trying to get the site back up and running. Am I missing something blatantly obvious here?

1 个答案:

答案 0 :(得分:0)

Declare variable be_link at the same level of window.open(be_link)

    var be_link = "";       
    ga(function(tracker) {
        var linker = new window.gaplugins.Linker(tracker);
        be_link = linker.decorate(target);
    });
    window.open(be_link);

OR try with:

    ga(function(tracker) {
        var linker = new window.gaplugins.Linker(tracker);
        var be_link = linker.decorate(target);
        window.open(be_link);
    });