user3108912
user3108912

Reputation: 1

jquery object expected error

I have a problem with jquery error in IE6-8 when clicking on button removing input. The webbrowser gives me error message "object expected"

Any tips to solve this kind of problem? I can share with my code which adds and removes inputs and it also counts the number of all inputs. I have used php to give information about current existing inputs with values. Is it possible that it is not working because of any syntax mistake in the jquery script or is it just wrong to include CDN for older IE webrowsers?

Thanks for all possible helps or tips.

It includes Google CDN:

<script language = "javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>

this is the whole jquery script:

$(document).ready(function () {
    var maxTags = 20;
    var tagsDiv = $("#newTagsDiv");
    var addTag = $("#addTagButton");
    var removeTag = $("#removeTagButton");

    var x = tagsDiv.length + <? php print $tagNumber; ?> -1;
    var tagNumber = <? php print $tagNumber; ?> -1;

    $(addTag).click(function (e) {
        if (x <= maxTags) {
            tagNumber++;
            $(tagsDiv).append('<div id="tagDiv' + tagNumber + '"><span class="tagNumber">' + tagNumber + '.</span><input type="text" name="tag' + tagNumber + '" id="tag' + tagNumber + '" size="20" value=""/></div>');
            x++;
        }
        return false;
    });

    $(removeTag).click(function (e) {
        if (x > 1) {
            $('#tagDiv' + tagNumber).remove();
            x--;
            tagNumber--;
        }
        return false;
    });
});

Upvotes: 0

Views: 2249

Answers (1)

Jonast92
Jonast92

Reputation: 4967

Replace

<script language = "javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>

with

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

And have it inside of your head.

This seems to be a common problem in newer versions of IE, that is, it actually forced you to do it the "proper way".

Upvotes: 0

Related Questions