Jump to content

JAVASCRIPT inside PHP funtion


thisisnuts123

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.