Jump to content

Recommended Posts

Hello all i am trying to echo out javascript funtion inside php any ideas how can this be done?

there is the code

 

/*

 

function update_dropbox($data_array, $col_check)

{

      $i = 0;

$o = array();

foreach($data_array AS $set => $items)

{

foreach($items AS $item)

{

$item = mysql_escape_string($item);

      $set  = mysql_escape_string($set);

$o[$i] = $items[$i];

 

      $query  = "SELECT `site` FROM table WHERE `item` = '$o[0]'";

      $result = mysql_query($query);

      $row = mysql_fetch_row($result);

      $value = $row[0];

      $i ++;

  }

}

 

 

 

return $value;

 

}

*/

 

 

how can i echo an javascript alert of the variabe "$o[0]"

 

Thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/
Share on other sites

this whole thing is a funtion

but when i run the site the page pops up without me calling the funtion

how can i make it only pop up once the funtion is called

 

 

/*

<?php

function update_dropbox($data_array, $col_check)

{

      $i = 0;

$o = array();

foreach($data_array AS $set => $items)

{

foreach($items AS $item)

{

$item = mysql_escape_string($item);

      $set  = mysql_escape_string($set);

$o[$i] = $items[$i];

 

      $query  = "SELECT `site` FROM table WHERE `item` = '$o[0]'";

      $result = mysql_query($query);

      $row = mysql_fetch_row($result);

      $value = $row[0];

      $i ++;

  }

}

if( $value != NULL )

        {

           

echo "<script type=\"text/javascript\">\n";

echo "<!--\n";

echo " window.open(\"modules/$name/copyright.php\",\"Copyright\",\"toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=200\");\n";

echo "//-->\n";

echo "</script>\n\n";

}

return $value;

 

}

 

 

?>

*?

i think i have the code right!!

as my debuger picks up the alert!!

is it posible to send an alert out from php funtion..

as i do not see any alerts

 

 

my page starts of with

 

<?php ...

 

blah blah

 

function update_dropbox($data_array, $col_check)

{

     

blah blah

?> 

<script script type="text/javascript">

var site="<?= $value ?>";

alert(site);   

</script>

 

<?php

 

}

 

this should pick up value insert it in to variable site and send an alert out.. only when the php funtion is called.

in my debuger i do see the java variable "site" geting updated.. but it does not send the alert out any ideas why?

ok perfect thanks!!



<?php ...

blah blah

function update_dropbox($data_array, $col_check)
{
         
blah blah
?>  
   <script script type="text/javascript">
   var site="<?= $value ?>";
   alert(site);     
   </script>
      
<?php   
      
}

 

 

any idea why this will not pop up an alert?

is this becuas it;s in an php funtion?

if so is there a way around it?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.