PHP - Variable Conversion Php To Javascript
Hi;
I'm a beginner and I'm getting a big headache figuring how to convert php variables into Javascript variables. I want to use the content of $theName as the value for an input tag. $_SESSION['$Sess_Name'] is loaded with the right data, I verified it. But my function InitField returns always the word NULL. Why is that? Where is the problem? Thank Here is my code: function InitField() { <?php Similar TutorialsHi i have this scroolbar javascript where you implement the text inside the java variable but because i want the data to come from the database i wanted to use a php example <? print($marker); ?> so i was wondring if it is possible to add a php variable into a javascript like this my javascript at moment the javascript variable is like this Code: [Select] var myMainMessage=" Try this out! The message just keeps repeating. Use it for announcements, news and other items! ";i want to change to this Code: [Select] var myMainMessage="<? print($marker); ?>";is it possible if so can someone show me an example thanks the whole javascript Code: [Select] <SCRIPT LANGUAGE="JavaScript"> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- (c) http://www.wyka-warzecha.com --> <!-- Begin // THESE VARIABLES where i want to add the php // var myMainMessage=" Try this out! The message just keeps repeating. Use it for announcements, news and other items! "; var speed=150; var scrollingRegion=50; // END CHANGEABLE VARIABLES // var startPosition=0; function mainTextScroller() { var mainMessage=myMainMessage; var tempLoc=(scrollingRegion*3/mainMessage.length)+1; if (tempLoc<1) {tempLoc=1} var counter; for(counter=0;counter<=tempLoc;counter++) mainMessage+=mainMessage; document.mainForm.mainTextScroller.value=mainMessage.substring(startPosition,startPosition+scrollingRegion); startPosition++; if(startPosition>scrollingRegion) startPosition=0; setTimeout("mainTextScroller()",speed); } // End --> </script> I have this javascript code which uses mouseover for a tooltip. It works fine until i add php. Anyone know how i could add the php variable? Here is the original code: <span class="users_browsing" onmouseover="tooltip.show('hi');" onmouseout="tooltip.hide();"> Ive tried this but it doesnt work: echo "<span class=\"users_browsing\" onmouseover=\"tooltip.show(\"{$content1}\");\" onmouseout=\"tooltip.hide();\"> Users Browsing Forum: {$browsers_num}</span>"; can i add php variables into a js file? i have tried this: document.location = <?php echo $_SESSION['fwd_page']; ?>; but it doesnt work. Hi everybody! I am new to php, I'm trying to read a php variable using javascript function my code is as follow: <?php $php_var = 100; ?> <SCRIPT type="text/javascript"> var js_var = "<?php =$php_var; ?>"; function display_var() { alert(js_var); } </SCRIPT> <body onload="display_var()"> .......... .......... </body> the problem is that the line alert(js_var); gives me "<?php =$php_var; ?>" instead of 100. I don't know what I'm missing. any help would be greatly appreciated. Thanks in advance. Well this is the code I currently have, it is derived from ajax organic tabs codes. Code: [Select] <? if($filename == "profile"){ ?> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script> <script src="js/tabs.js"></script> <script> $(function() { $("#profile").organicTabs(); }); </script> <? } ?> It may look fine this way, but rather inflexible if I wish to implement more tabs in future instead of just for the profile page. Assuming I have profile.php, members.php and stats.php and all of the three script files use tab system, the codes will become: Code: [Select] <? if($filename == "profile"){ ?> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script> <script src="js/tabs.js"></script> <script> $(function() { $("#profile").organicTabs(); }); </script> <? } elseif($filename == "members"){ ?> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script> <script src="js/tabs.js"></script> <script> $(function() { $("#members").organicTabs(); }); </script> <? } elseif($filename == "stats"){ ?> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script> <script src="js/tabs.js"></script> <script> $(function() { $("#stats").organicTabs(); }); </script> <? } ?> Which can get even more tedious as more and more pages needs to adopt tabs system. I wonder if there is a way to simplify the code by passing the php variable $filename directly into javascript tabs definition in this line, where the part $("#profile") changes as filename changes? Please help... Code: [Select] $("#profile").organicTabs(); Okay, I have been looking into this for the last 3 hours, and cant find shit. I have a page with a javascript game where the player moves around on a map. They have an X and Y coordinate, but I'm having a problem. The problem is I need to store that info in a database, and I'm having trouble learning AJAX. Heres a little list of things: Play loads the game. A php variable is taken from a database. The player goes to those X and Y coordinates. The player may move around. Once they move, the player is sent to a php page that updates the Database information. The page is refreshed to the game again, where they may then move around some more. The problem is, when the page is changed the values are lost. For some reasons cookies aren't working at all (like just not working for anything, even a completely different file.) I heard something about using $_GET or $_POST, but I dont see how... hi is it possible to post a variable like this either with javascript or php query.php Code: [Select] <?php include("../../includes/config.php"); mysql_connect($db_address, $db_username, $db_password);mysql_select_db($db_name) or die(mysql_error()); $fid = $_GET['fid']; $fid = mysql_real_escape_string($fid); $query10 = "SELECT * FROM films WHERE (film_id = '$fid')"; $qry_result10 = mysql_query($query10) or die(mysql_error()); while($row10 = mysql_fetch_array($qry_result10)) { $urlfid="http://www.onfilm.biz/streaming/home/".$row10['client']."/".$row10['client_office']."/".$row10['filename'].".mp4";?> <a class="hofwhite14" href="#" onclick="loadNplay('<?php echo $urlfid; ?>')"><u></u>Property Film</u></a> <?php }mysql_close(); //EDIT 290510 ?> <script type="text/javascript"> var video= $urlfid; $.post('indextest.php', {urlfid:video}); </script> I'm making a site where I use a javascript popup, and I want to pass in a php variable to the popup, but I'm not sure what to do. Normally, I would use $_GET but the link points to the javascript code. Basically, I want the popup to display which user was clicked, player 1 or player 2, but I don't know where to start. Sorry if this should be asked in a javascript forum, I wasn't sure who I should ask. If I've asked in the wrong place, let me know. Test.php Code: [Select] <html> <head> <script type="text/javascript" src="script/popup-window.js"></script> </head> <body> <?php $player1 = "abc"; $player2 = "def"; $javacode = "javascript:popup_show('popup', 'popup_drag', 'popup_exit', 'screen-top-left', 1200, 20)"; echo 'Player 1: <a href="'.$javacode.'">'.$player1.'</a><br />'; echo 'Player 2: <a href="'.$javacode.'">'.$player2.'</a><br />'; ?> <div class="sample_popup" id="popup" style="display: none;"> <?php echo "Player selected: "; ?> </div> </body> </html> script/popup-window.js Code: [Select] // Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved. // Technical support: http://www.php-development.ru/ // // YOU MAY NOT // (1) Remove or modify this copyright notice. // (2) Re-distribute this code or any part of it. // Instead, you may link to the homepage of this code: // http://www.php-development.ru/javascripts/popup-window.php // // YOU MAY // (1) Use this code on your website. // (2) Use this code as part of another product. // // NO WARRANTY // This code is provided "as is" without warranty of any kind. // You expressly acknowledge and agree that use of this code is at your own risk. // USAGE // // function popup_show(id, drag_id, exit_id, position, x, y, position_id) // // id - id of a popup window; // drag_id - id of an element within popup window intended for dragging it // exit_id - id of an element within popup window intended for hiding it // position - positioning type: // "element", "element-right", "element-bottom", "mouse", // "screen-top-left", "screen-center", "screen-bottom-right" // x, y - offset // position_id - id of an element relative to which popup window will be positioned // ***** Variables ************************************************************* var popup_dragging = false; var popup_target; var popup_mouseX; var popup_mouseY; var popup_mouseposX; var popup_mouseposY; var popup_oldfunction; // ***** popup_mousedown ******************************************************* function popup_mousedown(e) { var ie = navigator.appName == "Microsoft Internet Explorer"; popup_mouseposX = ie ? window.event.clientX : e.clientX; popup_mouseposY = ie ? window.event.clientY : e.clientY; } // ***** popup_mousedown_window ************************************************ function popup_mousedown_window(e) { var ie = navigator.appName == "Microsoft Internet Explorer"; if ( ie && window.event.button != 1) return; if (!ie && e.button != 0) return; popup_dragging = true; popup_target = this['target']; popup_mouseX = ie ? window.event.clientX : e.clientX; popup_mouseY = ie ? window.event.clientY : e.clientY; if (ie) popup_oldfunction = document.onselectstart; else popup_oldfunction = document.onmousedown; if (ie) document.onselectstart = new Function("return false;"); else document.onmousedown = new Function("return false;"); } // ***** popup_mousemove ******************************************************* function popup_mousemove(e) { var ie = navigator.appName == "Microsoft Internet Explorer"; var element = document.getElementById(popup_target); var mouseX = ie ? window.event.clientX : e.clientX; var mouseY = ie ? window.event.clientY : e.clientY; if (!popup_dragging) return; element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px'; element.style.top = (element.offsetTop +mouseY-popup_mouseY)+'px'; popup_mouseX = ie ? window.event.clientX : e.clientX; popup_mouseY = ie ? window.event.clientY : e.clientY; } // ***** popup_mouseup ********************************************************* function popup_mouseup(e) { var ie = navigator.appName == "Microsoft Internet Explorer"; var element = document.getElementById(popup_target); if (!popup_dragging) return; popup_dragging = false; if (ie) document.onselectstart = popup_oldfunction; else document.onmousedown = popup_oldfunction; } // ***** popup_exit ************************************************************ function popup_exit(e) { var ie = navigator.appName == "Microsoft Internet Explorer"; var element = document.getElementById(popup_target); popup_mouseup(e); element.style.display = 'none'; } // ***** popup_show ************************************************************ function popup_show(id, drag_id, exit_id, position, x, y, position_id) { var element = document.getElementById(id); var drag_element = document.getElementById(drag_id); var exit_element = document.getElementById(exit_id); var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight; element.style.position = "absolute"; element.style.display = "block"; if (position == "element" || position == "element-right" || position == "element-bottom") { var position_element = document.getElementById(position_id); for (var p = position_element; p; p = p.offsetParent) if (p.style.position != 'absolute') { x += p.offsetLeft; y += p.offsetTop; } if (position == "element-right" ) x += position_element.clientWidth; if (position == "element-bottom") y += position_element.clientHeight; element.style.left = x+'px'; element.style.top = y+'px'; } if (position == "mouse") { element.style.left = (document.documentElement.scrollLeft+popup_mouseposX+x)+'px'; element.style.top = (document.documentElement.scrollTop +popup_mouseposY+y)+'px'; } if (position == "screen-top-left") { element.style.left = (document.documentElement.scrollLeft+x)+'px'; element.style.top = (document.documentElement.scrollTop +y)+'px'; } if (position == "screen-center") { element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px'; element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight)/2+y)+'px'; } if (position == "screen-bottom-right") { element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth ) +x)+'px'; element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight) +y)+'px'; } drag_element['target'] = id; drag_element.onmousedown = popup_mousedown_window; exit_element.onclick = popup_exit; } // ***** Attach Events ********************************************************* if (navigator.appName == "Microsoft Internet Explorer") document.attachEvent ('onmousedown', popup_mousedown); else document.addEventListener('mousedown', popup_mousedown, false); if (navigator.appName == "Microsoft Internet Explorer") document.attachEvent ('onmousemove', popup_mousemove); else document.addEventListener('mousemove', popup_mousemove, false); if (navigator.appName == "Microsoft Internet Explorer") document.attachEvent ('onmouseup', popup_mouseup); else document.addEventListener('mouseup', popup_mouseup, false); Folks, Requirement: I want to pass Javascript Output in a PHP Variable. Purpose: So that i can find a particular String from that Javascript Output and accordingly apply the control. Javascript: Quote <script type='text/javascript'> var amzn_wdgt={widget:'Search'}; amzn_wdgt.tag='powlawofatt-21'; amzn_wdgt.columns='3'; amzn_wdgt.rows='10'; amzn_wdgt.defaultSearchTerm='10 mp 5x zoom'; amzn_wdgt.searchIndex='Electronics'; amzn_wdgt.width='542'; amzn_wdgt.showImage='True'; amzn_wdgt.showPrice='True'; amzn_wdgt.showRating='True'; amzn_wdgt.design='2'; amzn_wdgt.colorTheme='Default'; amzn_wdgt.headerTextColor='#000000'; amzn_wdgt.outerBackgroundColor='#FFFFFF'; amzn_wdgt.marketPlace='GB'; </script> <script type='text/javascript' src='http://wms.assoc-amazon.co.uk/20070822/GB/js/AmazonWidgets.js'> </script> What i am doing: Quote $javaoutput = "<script type='text/javascript'> var amzn_wdgt={widget:'Search'}; amzn_wdgt.tag='powlawofatt-21'; amzn_wdgt.columns='3'; amzn_wdgt.rows='10'; amzn_wdgt.defaultSearchTerm='10 mp 5x zoom'; amzn_wdgt.searchIndex='Electronics'; amzn_wdgt.width='542'; amzn_wdgt.showImage='True'; amzn_wdgt.showPrice='True'; amzn_wdgt.showRating='True'; amzn_wdgt.design='2'; amzn_wdgt.colorTheme='Default'; amzn_wdgt.headerTextColor='#000000'; amzn_wdgt.outerBackgroundColor='#FFFFFF'; amzn_wdgt.marketPlace='GB'; </script> <script type='text/javascript' src='http://wms.assoc-amazon.co.uk/20070822/GB/js/AmazonWidgets.js'> </script>"; if (strpos($javaoutput, "No results for")) { echo "Sorry no product found"; } else echo $javaoutput; Problem: It seems its outputting the Javascript output in PHP variable $javaoutput but the strpost() does not work. What am i doing wrong? and How to correct it? Cheers Natasha Thomas Hi, for my purposes, I can only use core PHP function (no PEAR for eg) to convert SQL to XML, should I convert SQL to csv first, and then use php's filesystem to read each line to extract and store as xml nodes OR does someone know easier/better method? Any help much appreciated, thanks. Can someone tell me how to convert a MySQL date such as 2010-08-13 into the the US format, such as 8/13/2010, and also the reverse using PHP? I can't seem to find the right functions. Thanks! I need to compare current time to data based time. Time in the database is in this format > 00:00:00 Easy enough. >>>>What I need is to convert "00:00:00" format into "time();" format<<<< The opposite is below...it's all I could come up with so far. <? $gettime = time(); $displayTime = date('H:i:s', time()); echo $displayTime; ?> Thank you. I don't really know how to explain this, I saw once on some forum members signature, something like this : G = "\ x50 \ x72 \ 157 \ 144 \ x75 \ x63 \ 164 \ x20 \ x6c \ x69 \ 143 \ 145 \ 156 \ x73 \ 145 \ 040 \ x68 \ 141 \ x73 \ 040 \ x65 \ x78 \ 160 \. 151 \ 162 \ x65 \ 144 \ x2e \ x20 "+ E. That somehow translates into words, I know there is a PHP function to convert that, what is that code called and what is the PHP function? I've been looking at converting my php timestamps to display as month, day, and the hour and minute the event occurred on, i tried; Code: [Select] $time = date("j/n H:i", $Events['timestamp']); But no success can anyone point me in the correct direction? Thanks I am writing a script to read a mail box and fetch mail body using php function "imap_fetchbody". If mail content encoding is UTF-8 then no problem but mail send from IPAd having ascii encoding and replace the new line with =20 along with many other changes. can anyone help me out with this in converting it to UTF-8 ?? I need a little help. I am trying to convert images taken from an upload form and convert them to jpg and then upload it to my directory. I tried GD but I cant figure out how to upload the converted file. I also tried using ffmpeg to convert the file but I am only able to do it with videos, I cant find the parameters for image to image conversion. Any input would be appreciated. Thanks Good evening, I hope some of you can bring me some hope to solve this problem. My client wants to create pdf files and let the user download it. He want's to design one word file and then import it to the application. After that the portal users can request it, which means that the application should take the word file, search and replace some keywords and then create the pdf file for download purposes. I see fpdf but this class only create pdf's. We can not convert from word or even search and replace in one pdf file. There is any solution that i can use bear in mind that our application is located in external servers? Looking forward for your help. Regards, HS Hello, Doing a little calendar where days are incremented as variable $i formatted like 'j' or single digit numbers 1,2,3 etc. (The calendar works fine) However for querying DB tables I need the day formatted as 'd' or 01,02,03 etc. so on any day I need to make this conversion. I can't find an easy solution though there must be one. Thanks in advance. Code: [Select] <?php //test day $i=7; $day=date('d', mktime($i)); echo "$day"; //Should be 07 ?> Hello Freaks, Is there any possible way to convert a .PDF file to .html file without using any third party app and API?. I need That conversion fully made by PHP. Because i want to have full control on that conversion Help me with your opinion.. Thank You
|