thisisnuts123 Posted October 14, 2007 Share Posted October 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/ Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 erm.. like this echo $o[0]; other example <?php echo '<script language="javascript">alert("test");</script>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369542 Share on other sites More sharing options...
npsari Posted October 14, 2007 Share Posted October 14, 2007 or just stop the php in the middle and start it again, it works! like that... <? php stuff ?> Your Javascript <? php stuff ?> Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369546 Share on other sites More sharing options...
thisisnuts123 Posted October 15, 2007 Author Share Posted October 15, 2007 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; } ?> *? Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369563 Share on other sites More sharing options...
SirChick Posted October 15, 2007 Share Posted October 15, 2007 please put your code in tags makes life a bit easier to read =/ Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369567 Share on other sites More sharing options...
thisisnuts123 Posted October 15, 2007 Author Share Posted October 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369611 Share on other sites More sharing options...
thisisnuts123 Posted October 15, 2007 Author Share Posted October 15, 2007 sorry i am new to this site i duuno how to put the code in tags so it;s nice and easy to read Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369612 Share on other sites More sharing options...
kenrbnsn Posted October 15, 2007 Share Posted October 15, 2007 Put the tag [/b] before the start of the code snippet and [b] after it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369620 Share on other sites More sharing options...
thisisnuts123 Posted October 15, 2007 Author Share Posted October 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369641 Share on other sites More sharing options...
roopurt18 Posted October 15, 2007 Share Posted October 15, 2007 You repeated the word script in your script tag, remove the duplicate. Quote Link to comment https://forums.phpfreaks.com/topic/73249-javascript-inside-php-funtion/#findComment-369664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.