CodeIgniter Forums
Java Popup Window ain't working in php code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Java Popup Window ain't working in php code (/thread-53141.html)



Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]jonnyG[/eluser]
hey there,
I'm just writing a little formular, if something is not completly filled out there should show up a little java alert window...

Controller
Code:
$this->form_validation->set_rules('name', 'Name', 'required');


  if ($this->form_validation->run() == FALSE)
  {
   $alert['bool'] = true;
   $alert['message'] = "ooops something missing!";
   print_r($alert);
   $this->load->view('header');
   $this->load->view('pages/req', $alert);
   $this->load->view('footer');
  }
  else
  {
   $alert['bool'] = true;
   $alert['message'] = "Your request was send!";

   $this->load->view('header');
   $this->load->view('req', $alert);
   $this->load->view('footer');
  }

View
Code:
<?php
if($bool == true){?>
[removed]
function myFunction()
{
alert(<?=$message?>);
}
[removed]

<?php  
}
?>

print_r($alert); --> Array ( [bool] => 1 [message] => ooops something missing! )

any idea where the problem could be?
the [removed] stands for javascript....



Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]InsiteFX[/eluser]
Maybe php short open tags are turned off.
Code:
alert(<?php echo $message;?>);



Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]jonnyG[/eluser]
no thats not the problem.. using it nearly everywhere where using variables


Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]InsiteFX[/eluser]
To display the message you have to be calling the myFunction someplace but I do not see you calling.

Maybe your not showing all the code.



Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]guzzilar[/eluser]
in js code try

Code:
var msg = <?=$message;?>;

function test(msg)
{
     alert(msg);
}

try this :)


Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]jonnyG[/eluser]
ah okay! I change it to

Code:
<?php
if($bool == true){
echo myFunction();
}
?>

function
Code:
[removed]
function myFunction()
{
alert(<?php echo $message; ?>);
}
[removed]

but now I just get a blank page with the output from the array.. ??



Java Popup Window ain't working in php code - El Forum - 07-12-2012

[eluser]jonnyG[/eluser]
Code:
<?php
if($bool == true){
echo do_alert($message);
}
?>

<?php
function do_alert($message)
    {
        echo '[removed]alert("' . $message . '"); [removed]';
    }
?>


solved it this way now..
but if the popup shows up some areas in the back are missing(looks weird)