Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » JQUERY JTABLE

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3 4
Go to End
Author Topic: 8076 Views
  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: JQUERY JTABLE Link to this post

    Am I understanding you correctly that writing it like this:
    var $img = $('<img src=\"mysite/javascript/phone.jpg\" title=\"Edit phone numbers\" />');
    Instead of the way it's written in your post gives you an error?

    Also when writing code like that I'd really recommend you to switch to '' instead of "". When using "" every time the $ sign pops up PHP will think that's a variable and try for a variable replacement which probably isn't what you want. Start off by delimiting the whole customScript() in '' and change that line to:
    var $img = $("<img src=\'mysite/javascript/phone.jpg\' title=\'Edit phone numbers\' />");

    Finally, unless you really really have to, adding code through Requirements::customScript is really not recommended. You get problems like the ones you're having now and you're mixing PHP and js code which isn't a very good idea.

  • sergieboy
    Avatar
    Community Member
    33 Posts

    Re: JQUERY JTABLE Link to this post

    Correct.
    Without escaping : you get a syntax error.
    With escaping : you get a 'missing variable name' error:
    var = $('<img src=\"mysite/javascript/phone.jpg\" title=\"Edit phone numbers\" />');
    It's like the $img disappeared from the FireBug screen.

    I tried any kind of switching "" '', doesn't help.

    When I start off by delimiting the whole customScript() in '' , there are a dozen of other error occuring.

    "Finally, unless you really really have to, adding code through Requirements::customScript is really not recommended. You get problems like the ones you're having now and you're mixing PHP and js code which isn't a very good idea." Are you suggesting that I should include the javascript in the template ?

    Attached Files
  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: JQUERY JTABLE Link to this post

    Yes either include the js in the template directly or simply link it as a custom external script. Are you depending on any variables from PHP in that customScript() function?

  • sergieboy
    Avatar
    Community Member
    33 Posts

    Re: JQUERY JTABLE Link to this post

    Not depending on any variables from PHP in that customScript() function.
    Will try it by linking it as an external custom script.

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: JQUERY JTABLE Link to this post

    Just my 2 cts worth, if ever you want to use customScript again:

    I try and avoid javascript variables beginning with a $.

    Also there is an issue, where you use a jQuery selector $(...) between brackets, like in: function(){$('ul').css('color','#ffffff');} SilverStripe, seeing the {$ bit, will now consider it a PHP variable and throw an error. Adding a space the bracket and dollarsign will fix that.

    Happened to me lots of times

    8076 Views
Page: 1 2 3 4
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.