1 Replies - 777 Views - Last Post: 11 September 2013 - 01:09 AM Rate Topic: -----

#1 insik  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 74
  • Joined: 31-January 12

Putting Function Inside Quotes

Posted 11 September 2013 - 12:42 AM

Hi everyone. just wanna ask if it is possible to put a js function inside quotes.
$result_final .= "
<table width='50%' border=1 cellpadding='9' cellspacing='5' style='position:absolute;top:5%;right:8%;'>
<tr><td>$ ".number_format($row[3])."</td></tr>
<tr><td><input type='image' src='images/cartbutton.png' value='Add to Cart'onclick='".addtocart($row[0])."' /></td></tr>

if not. what are other ways?
thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Putting Function Inside Quotes

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4188
  • View blog
  • Posts: 13,236
  • Joined: 08-June 10

Re: Putting Function Inside Quotes

Posted 11 September 2013 - 01:09 AM

regarding the example, the functions are not inside the quotes/strings.

if you put functions inside a string, they won’t be parsed automatically (how should PHP know the difference of a Java­Script function call and a PHP function call?). you can however parse the string yourself for a function call (with said drawbacks) and execute the function (though that is—again—outside the string).

an, IMHO better, option is to use a template. in the simplest case: printf() (and related, cf. examples).
printf($template, $myVariable, myFunction($data));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1