Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts

    escaping html in Jquery

    I am creating an append based upon a php function. The append is part of the function, however despite escaping the jquery the functions is stripping out the escapes causing errors. How can I stop this??

    PHP Code:
    $buttonCreate = function($buttonID$appendID$appendChkBox$appendDate$appendDateInput$appendDateValue$appendTitle$appendTitleInput$appendTitleValue$appendCost$appendCostInput$appendCostValue )
    {
        
        return 
    sprintf("<script> $('#%s').click(function() {
          $(\"#%s\").append(\"<tr><td><input type=\'checkbox\' name=\"%s\" /></td><td>%s<input type=\"hidden\" name=\"%s\" value=\"%s\"></td><td></td><td>%s<input type=\"hidden\" name=\"%s\" value=\"%s\"></td><td></td><td></td><td></td><td>%s<input type=\"hidden\" name=\"%s\" value=\"%s\"></td><td></td><td></td><td></td></tr>\");  });</script>"
    $buttonID$appendID$appendChkBox$appendDate$appendDateInput$appendDateValue$appendTitle$appendTitleInput$appendTitleValue$appendCost$appendCostInput$appendCostValue);
    }; 
    The error I am getting is

    PHP Code:
    Syntax error at line 3 while loadingexpected ')'got 'new_chk_34'
    =checkbox name="new_chk_34" /></td><
    --------------------^ 
    This relates to the checkbox within append, ARGH!!!!

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Check server settings to make sure magicquotes isn't interfering with anything.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Nope, its off..

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    type=\'checkbox\'

    If the string delimiter is ", you don't need to escape '.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Thanks, in the end went with holding it in a var, which is then called to the append

    PHP Code:
    $buttonCreate = function($buttonID$appendID$appendChkBox$appendDate$appendDateInput$appendDateValue$appendTitle$appendTitleInput$appendTitleValue$appendCost$appendCostInput$appendCostValue )
    {
        
        return 
    sprintf("<script> 
          var form = $('<tr><td><input type=\"checkbox\" name=\"%s\" /></td><td>%s<input type=\"hidden\" name=\"%s\" value=\"%s\"></td><td></td><td>%s<input type=\"hidden\" name=\"%s\" value=\"%s\"></td><td></td><td></td><td></td><td>%s<input type=\"hidden\" name=\"%s\" value=\"%s\"></td><td></td><td></td><td></td></tr>');
          $('#%s').click(function() {
          $(\"#%s\").append(form);  });</script>"
    $buttonID$appendID$appendChkBox$appendDate$appendDateInput$appendDateValue$appendTitle$appendTitleInput$appendTitleValue$appendCost$appendCostInput$appendCostValue);

    }; 

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,606
    Thanks
    6
    Thanked 997 Times in 970 Posts
    I might add that the way you wrote/formatted that code is very messy and hard to maintain. You should rather store the HTML in a PHP variable and use heredoc notation, for example.

  • #7
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Thanks for that Stephen, have used this feature previously to good effect, will make the changes.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •