Andrew H
Andrew H

Reputation: 453

Jquery, 'invalid or unexpected token'. Not a string issue

I'm a newbie to javascript and jquery, and this bug has been hounding me for almost a day. Here's the code:

    $('#txtTabContentsHeight', '#ddlTabContentsHeightRuler').blur(function ()
    {
      //need to check ruler val first!
      var sruler = $('#ddlTabContentsHeightRuler').children("option").filter(":selected").text‌​().toLowerCase();
      var sval = $('#txtTabContentsHeight').val(); + '' + sruler;
      ChangeTabContentsCss(this, 'height');
    });

I get a jquery error in my browser console on the $('#ddl...').^^children(... line. Even if I do a $('#ddlTabContentsHeightRuler').val(), I get the same error on the '.' of invalid or unexpected token.

I've checked every single similar discussion here and on the web for this kind of error, and it's always about a string issue, or a syntax issue. But for the life of me, I can't see a syntax problem here. The ddl element is a select element, obviously.

Can someone smack me upside the head with an answer?

Upvotes: -1

Views: 1407

Answers (4)

Twista
Twista

Reputation: 19

As earlier suggested, you could use with cross checking your html code especially the id names of the elements being selected

Upvotes: 0

Andrew H
Andrew H

Reputation: 453

Well, as usual when I have these kinds of errors, if I just RETYPED the whole line, the bug disappeared! I actually did an undo, and tried to delete every single character on the original line, to see if I had some 'hidden characters' or something...and NOPE. Still got the error, though the line looked EXACTLY the same as the one that works.

Is this usual with jquery/javascript? That's sort of unacceptable as a programmer...

Upvotes: 0

Twista
Twista

Reputation: 19

did u need the semi-colon on $('#txtTabContentsHeight').val(); + '' + sruler;or $('#txtTabContentsHeight').val() + '' + sruler;

Upvotes: 0

ACFK
ACFK

Reputation: 66

Try changing .text() for .val() or .html(). The .text() method cannot be used on form inputs

Upvotes: 1

Related Questions