egturnkey Posted March 16, 2010 Share Posted March 16, 2010 Hello friends, If i do have a database table and the following <?=$ama[Terms]?> this is meaning we have a table with feild called "terms" then how we can insert it into javascript for example window.onload = function() {setTimeout(showIt, <?=$ama[Terms]?>);}; i mean how to add php code within javascript ! thanks Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/ Share on other sites More sharing options...
TecBrat Posted March 16, 2010 Share Posted March 16, 2010 You echo it like window.onload = function() {setTimeout(showIt, <?php echo($ama[Terms]); ?>);}; The server will parse it so that it is presented to the browser as window.onload = function() {setTimeout(showIt, whatever terms is);}; Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/#findComment-1026948 Share on other sites More sharing options...
MatthewJ Posted March 16, 2010 Share Posted March 16, 2010 window.onload = function() {setTimeout(showIt, <?php echo $ama["Terms"]; ?>);}; Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/#findComment-1026969 Share on other sites More sharing options...
KevinM1 Posted March 16, 2010 Share Posted March 16, 2010 Also, just because this is a pet peeve of mine, JavaScript != Java. Aside from name, the two have nothing to do with one another. They're not even made by the same people. Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/#findComment-1026971 Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 16, 2010 Share Posted March 16, 2010 If it's a string, you'll need quotes around it. Of course, then you'll need to either escape the quote in the PHP variable, or convert it to the HTML equivalent. Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/#findComment-1026988 Share on other sites More sharing options...
Andy-H Posted March 16, 2010 Share Posted March 16, 2010 For the record, the code examples you have all given do exactly the same as the OP's posted code, <?= $var; ?> is shorthand for <?php echo $var; ?> and the semicolon isn't necessary before the closing PHP tag. Although, using short tags is bad practice if you wish for your php code to be portable as PHP short tags can be disabled in the ini file. Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/#findComment-1027005 Share on other sites More sharing options...
MatthewJ Posted March 16, 2010 Share Posted March 16, 2010 For the record, I was just fixing the missing quotes around the column name in the echo so mine wasn't the same Quote Link to comment https://forums.phpfreaks.com/topic/195421-php-in-java/#findComment-1027097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.