Welcome Guest, Not a member yet? Register   Sign In
Java Popup Window ain't working in php code
#1

[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....
#2

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

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

[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.
#5

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

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

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

try this :)
#6

[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.. ??
#7

[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)




Theme © iAndrew 2016 - Forum software by © MyBB