-1

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?

7
  • If you're getting an error on $('#ddlTabContentsHeightRuler').val(), it would suggest that the problem is in the HTML (possibly a missing quote). It might be helpful if you can post it, here. Commented Oct 15, 2016 at 18:19
  • $('#ddlTabContentsHeightRuler').children("option").filter(":selected").text‌​() this is not returning a string Commented Oct 15, 2016 at 18:23
  • 1
    What is $('#txtTabContentsHeight', '#ddlTabContentsHeightRuler') supposed to do? Did you mean $('#txtTabContentsHeight, #ddlTabContentsHeightRuler')? Commented Oct 15, 2016 at 18:26
  • I am attaching a function to both of those elements. It works on any other element I work with, but not for the code above... Commented Oct 15, 2016 at 20:44
  • Again, even if I just replace that line with var sruler = $('#whatever').val() I STILL get the same 'invalid token' error on that line! It's bizarre, and I know I am doing something stupid, but can't see it. Commented Oct 15, 2016 at 20:45

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Oh. No that doesn't work either. As I said in my question:
Even when I do: var sruler = $('ddlTabContentsHeightRuler').val() I get an error of 'invalid token' on the line. It's baffling!
$('#txtTabContentsHeight', '#ddlTabContentsHeightRuler').blur(function () { //need to check ruler val first! var sruler = $('#ddlTabContentsHeightRuler').val(); //above doesn't work either. Same error of 'invalid token' on the var sruler... line var sval = $('#txtTabContentsHeight').val() + '' + sruler; ChangeTabContentsCss(this, 'height'); });
no, try to change just the .text(), var sruler = $('#ddlTabContentsHeightRuler').children("option").filter(":selected").val​().toLowerCase();
Yeah, again. I appreciate the response but as I state above, even if I just do: var sruler = $('#whatever').val(); I still get the same 'token' error.
0

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

2 Comments

Yeah, that's a typo, but it doesn't fix anything. Still get the error on the line above it. Is this really a hard thing to diagnose? If so, I'm in big trouble...
That semi-colon isn't in my original code...just there because I was typing all kinds of stuff trying to get it to work...when I went to try to put it back into the original state, which is where the error started, I accidentally added that typo...
0

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...

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.