0

I am trying to implement a plugin:

$(".myTbl th:nth-child(1)").truncate({
        width: "200",
        after: "…",
        center: false,
        addtitle: true
});

Instead of using a fixed value for width, I have a script that calculates it dynamically and sets it into a a variable, but when I plug it in the code breaks. What am I missing? it is all withing PHP code

echo '

var myWidth = 150;

$(".myTbl th:nth-child(1)").truncate({
        width: myWidth ,
        after: "…",
        center: false,
        addtitle: true
}); ';
6
  • Have you tried to debug it? Do you have an error? Commented Dec 2, 2011 at 17:46
  • There is nothing wrong with the code you posted, so the issue is somewhere else. Commented Dec 2, 2011 at 17:47
  • Perhaps the plugin expects a string and in the second snippet you're supplying it a number. Commented Dec 2, 2011 at 17:47
  • Maybe the plugin is expecting a string? Commented Dec 2, 2011 at 17:48
  • @Andrew Whitaker If I replace myWidth with "150" it works fine... It does not produce any errors, but the browsers keeps on spinning like it's waiting for something. It goes away as soon as I hard-code a numeric value. Weird, hah? Commented Dec 2, 2011 at 17:50

1 Answer 1

1

Perhaps the plugin is expecting a string literal.

serverside:

echo '

    $(".myTbl th:nth-child(1)").truncate({
        width: "150" ,
        after: "…",
        center: false,
        addtitle: true
    }); 
';

  js side:

echo '

    var myWidth = "150";

    $(".myTbl th:nth-child(1)").truncate({
        width: myWidth ,
        after: "…",
        center: false,
        addtitle: true
    }); 
';
Sign up to request clarification or add additional context in comments.

2 Comments

That was my thought too. You could also just quote your value when setting it to myWidth. var myWidth = "150";
@idrumgood I think your solution is better. @mrtsherman Your code will cause a parse error in PHP unless I'm reading incorrectly. The width line should read width: myWidth.toString(),.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.