Reputation: 261
i have a problem with javascript. i´d like to use colorbox to display some responsemessages. is there anyone who knows how to refer to a php script variable within a javascript?
to bring an example
<?php if(isset($msg)):?>
<script type="text/javascript">
$(document).ready(function(){
$.colorbox({iframe:true, href:"<?php print variable $message from this site", scrolling:false, innerWidth:"408px", innerHeight:"292px", opacity:0.75, overlayClose:false, escKey:false, });
});
$("#colorboxCloseBtn").click(function() {
$.colorbox.close();
});
</script>
<?php endif; ?>
i´m not sure if i do understand the usage of iframe, inline, html. if i use iframe this will open a complete idependent site without any relation to the mainpage, isn´t it? inline i use, when i would like to relate on content which is on the mainpage, like i like to, right? and html... don´t know.
thanks for help.
Upvotes: 0
Views: 1508
Reputation: 1420
no, this is barking up the wrong tree the way you're doing this, you need to put message into a session then have href get the full url of the new file then have that file echo nothing but $message:
//EG:your.php
<?PHP
session_start();
$_SESSION['message'] = $message;
if(isset($msg)) {
?>
<script type="text/javascript">
$(document).ready(function(){
$.colorbox({iframe:true, href:"message_get.php", scrolling:false, innerWidth:"408px", innerHeight:"292px", opacity:0.75, overlayClose:false, escKey:false });
$("#colorboxCloseBtn").click(function() {
$.colorbox.close();
});
});
</script>
<?php
}
?>
then a whole new document
//EG: message_get.php
<?PHP
session_start();
echo $_SESSION['message'];
?>
to be honest i'd get rid of the iframe you probably don't need it because this is a very ineligant way of doing this. You look to me like you've learnt ASP.NET first
Upvotes: 2
Reputation: 38147
<?php if(isset($msg)):?>
<script type="text/javascript">
$(document).ready(function(){
$.colorbox({iframe:true, href:"<?php echo $message ?>", scrolling:false, innerWidth:"408px", innerHeight:"292px", opacity:0.75, overlayClose:false, escKey:false });
$("#colorboxCloseBtn").click(function() {
$.colorbox.close();
});
});
</script>
<?php endif; ?>
using <?php echo $message ?>
will be what you are after
I have moved the click
method inside the ready()
function too - this ensures the DOM element is ready before attaching the click handler.
I have also removed the last comma from escKey:false
in the colorbox
function call
Upvotes: 1