PHP - Embedding Javascript In Php
i want to change the content of my div tag dynamically using javascript in PHP. I am using the following technqiue but it is not working.
<?php echo "<script type='text/javascript'>\n"; echo "document.getElementById('mydiv').innerHTML = 'contents of div.......';"; echo "</script>"; ?> please guide me how can i do this Thanks, Best Regards, Nice Candy. Similar TutorialsI'm trying to Embed the images from Apple into my PHP file. Code: [Select] $phpobj = unserialize($response); if (is_array($phpobj)) { foreach ($phpobj['value']['items'] AS $key => $val) { printf("<div><p><a href=%s>%s</a></p><p>%s</p>\n", $val['link'], $val['title'], $val['description']); } } But the problem is that the image attribute is inside a Table and using something lile $val['img'] is not working. So anybody can help me with this. Here is the RSS feed format from which I'm importing Code: [Select] <item> <title>Dead Awake - Trailer</title> <link>http://trailers.apple.com/trailers/independent/deadawake/</link> <description>DEAD AWAKE is a seductive supernatural thriller starring Rose McGowan, Amy Smart and Nick Stahl set against the backdrop of a mysterious tragedy that shattered their lives a decade ago and which sets them on a path to uncover the truth that lies between the living and the dead.</description> <pubDate>Wed, 01 Dec 2010 00:00:00 PST</pubDate> <content:encoded><![CDATA[ <table> <tr valign="top"> <td width="67"><a href="http://trailers.apple.com/trailers/independent/deadawake/"><img src="http://trailers.apple.com/trailers/independent/deadawake/images/poster.jpg" width="65" height="97" border="0"></a></td> <td> </td> <td><a href="http://trailers.apple.com/trailers/independent/deadawake/"><span style="font-size: 16px; font-weight: 900; text-decoration: underline;">Dead Awake - Trailer</span></a><br /> <span style="font-size: 12px;">DEAD AWAKE is a seductive supernatural thriller starring Rose McGowan, Amy Smart and Nick Stahl set against the backdrop of a mysterious tragedy that shattered their lives a decade ago and which sets them on a path to uncover the truth that lies between the living and the dead.<br /><b>Directed by:</b> Omar Naim<br /><b>Starring:</b> Nick Stahl, Rose McGowan, Amy Smart, Ben Marten, Kim Grimaldi, Brian Lynner, Justin Marxen, James Serpento, Jack Mishler, Shane Simmons, Rachel Storey, Justin Urich, Andrea Leon, Livia Milano, Phyllis Mumford</span></td> </tr> </table> ]]></content:encoded> </item> HI I am trying to find solutions on how i am able to embed IP Screenshots into a website. Right now i am able to do so but only if i am connected to a certain internet network, then i would be able to see those IP Screenshots images. However if i am not connected to that network, the website are not able to show them. THANKS ALOT!! Hello. I've asked around in many places now, and I thought I'd ask here too. A few days ago I installed phpBB3 on my site, works like a charm. I used a plugin for wordpress to integrate phpbb to wordpress, all works great. Now my problem is to embed the forum to my wordblog page. I tried using a simple iFrame solution, and it worked almost, but there's a common iFrame problem. The height, it doesn't scale with the embedded page, instead it stays as a 100px high frame with a scroll bar. I've searched google for hours now, and tried every possible javascript and css/div-tag solution I came across. Nothing works. Are there any alternatives to this? I tried using <?php include('../phpBB3/index.php') ?> But I get errors. It might be because I'm including from another directory, so it might be worth giving a try to give the direct path somehow, but how? Anyway, are there any other solutions for this problem? OK, I've seen this done both ways and want to know which (if any) is the most secure way to do it... I've been coding my pages using echo statements to write HTML, such as: <?php echo "<p><strong>hello, World!</strong></p>"; echo "<p>You a $age year(s) old!</p> "; ... ?> and so on... but is this any better <?php <p><strong>Hello World!</strong></p> echo "<p><strong>You are $age year(s) old!</p>"; ?> Is one of these methods better than the other (using ECHO to write actual HTML statements out rather than just embedding them in the script without ECHO)? Which is the recommended method? I'm not sure if this is possible
Previously I had a problem of outputting rows of a specific query
This was the solution that was given to me
$txt .= $date . " " . $stratoparse . "\n\n";Where a while loop's results were concatenated to a single string What I would like to do is output the results in individual containers with controls such as dragging for repositioning / an x for deletion That's not what I'm here for in this post I want to embed youtube videos, so they are not just stored as links, rather a clickable video so if you have something like string.string2.string3.string4.string5.<iframe src="youtube"...>.string7.string8 how would that video be isolated and parsed / understood as a front end youtube video ? To provide a brief background in case you are wondering why in my right mind, I would want to do this... First it is the primary solution that comes to mind going off what already works Secondly, the purpose or point of the concatenated string comes from the "application" design which is a store and recall interface. Vague, I know. The website has multiple users and they all have access to a single database. They save random strings, whether they are paragraphs or links, possibly videos that are uploaded, etc... these are saved by a keyphrase, later recalled by searching that keyphrase. Currently the output is nothing more than a concatenated string, that was fine initially but some of my friends have been testing the website and they made suggestions which are good such as repositioning and deleting entries. Now I want to automatically parse youtube links into embedded videos... I'll probably use that explode "function" to disect the link and place the url within the src=" " Anyway, I have to look into this but if anyone has any thoughts I'd appreciate it. Edited by moose-en-a-gant, 11 January 2015 - 02:05 AM. Hello All,
I am strugling with embending standard smtp code within the one I have. As I am using PHP ocassionaly I have problem with this.
My code is to use mail function to send email through an form with email server installed on host system where the form and server are together.
I want this code to adapt to sth that can login to google account and use google external smtp protocol to send the content of the form defined in $headers
The problem is I am using self generated captcha that validates if the email is sent and all fields are filled (currently under tests what should be filled and not filled) and it works fine
This is my code that works on a local host server:
//Set up the email headers
//Set up the email content
// Required Fileds Validation
And would like sth like this in place of $mailer , but my way is not working The code I thought would be embeded into $mailer $mail->isSMTP();$mail->Host = 'smtp.googlemail.com'; //gmail SMTP server $mail->SMTPAuth = true; $mail->Username = 'GMAIL_USERNAME'; //username $mail->Password = 'GMAIL_PASSWORD'; //password $mail->SMTPSecure = 'ssl'; $mail->Port = 465; //SMTP port Any idea how to adapt it to my code are welcomed and appreciated,
Thanks
Edited April 29, 2019 by slawotrend Is there a performance or security issue when embedding HTML code to be written to a page using a series of ECHO statements within PHP? Here's two examples: <?php // Some PHP code echo "<p>Hello, World</p>\n"; // More php code ?> versus: <?php> // Some PHP script commands ?> <p>Hello World\n"; <?php // More PHP code ?> Is there a performance issue or potential security flaw that would make the first example any worse/better than the second? (Is one method more "secure" than the other method, I guess is what I'm asking?) I like the ease of just throwing in HTML within a PHP script without having toe escape quote marks, etc. But, I'm a bit concerned about security since whatever technique I use will be incorporated into a "commercial" production website. I'm trying to have a javascript confirm box pop up and confirm the intention to delete a record in a database. I think I'm having trouble calling the function within my PHP code, but not sure what exactly is wrong. The status bar shows something like "javascript:checkDelete(100, Title)" when I hover over the link and that seems right but nothing occurs when I click on it. Here is my code: Javascript Code: [Select] <script language="Javascript"> function checkDelete(b,Title){ var del=confirm("Are you sure you want to delete " + Title + " from the Database?"); if (del){ document.location="delete.php?mID=" + b + "&Title=" + Title; } } </script> PHP echo "<td><a href='Javascript:checkDelete(" . $row['mID'] . "," . $row['Title'] . ")'>"; echo "<img border=0 src='images/delete.gif'>" . "</a></td></tr>"; Anyone see my error? the script here is the simplest progress bar ever.. what I want is for the value of the mutiplier (so how fast it loads) to be a php varible pulled from the users file <html> <head> <script type="text/javascript"> function progress() { if (document.images["bar"].width < 400) { document.images["bar"].width += 5; document.images["bar"].height = 5; } else { clearInterval(ID); } } var ID; window.onload = function() { ID = setInterval("progress();", 500); } </script> </head> <body> <img src="black.gif" name="bar" /> </body> </html> POSSIBLE? I wonder whether someone may be able to help me please. I'm currently running the code below (originating from nearby.org.uk) to convert OS Grid References to Latitude and Longtiude co-ordinates. Code: [Select] function converttolatlng() { var gr = document.getElementById('osgridref').value; var osgb = new GT_OSGB(); if (osgb.parseGridRef(gr)) { var wgs84 = osgb.getWGS84(); document.getElementById('osgb36lat').value = wgs84.latitude; document.getElementById('osgb36lon').value = wgs84.longitude; } else { document.getElementById('osgb36lat').value = "n/a"; document.getElementById('osgb36lon').value = "n/a"; } } This code is run through a 'click' event from a button on a HTML form and then the record is saved to a mySQL database. However, once a month, I have a list of approx 20,000 OS Grid References which need converting and saving to the same mySQL database. To do this manually on a button click wouldn't be very practical, so I've been working on doing this automatically. I may very well be doing this the wrong way, but I've been using the PHP script below to extract the two pieces of information I need from the xml file, the first is the 'Name, and the second is the 'NGR', and it is this field that needs converting. Code: [Select] <? $objDOM = new DOMDocument(); $objDOM->load("scheduledmonuments.xml"); $Details = $objDOM->getElementsByTagName("Details"); foreach( $Details as $value ) { $Name = $value->getElementsByTagName("Name"); $name = $Name->item(0)->nodeValue; $NGR = $value->getElementsByTagName("NGR"); $ngr = $NGR->item(0)->nodeValue; echo "$name :: $ngr <br>"; } ?> This is where I've become a little stuck because I'm not sure how to get the data converted and to a point where it can be saved to the relevant fields in my database. I just wondered whether someone would perhaps take a look at this please and let me know what I need to do. Many thanks New to PHP/Java. Need some help!!! I need the textarea of a site to save what is entered into a text file. I also need javascript to use a pre-validate pop up box, if no data is entered. I can't get both of them to work at the same time. Below is my code. Code: [Select] <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <script type="text/javascript"> <!-- <!CDATA[ function validateForm() { var x=document.forms["myForm"]["email"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } // ]]> --> </script> </head> <form name="form1" method="post" action="index2.php?saving=1"> <textarea name="data" cols="100" rows="10"> Username: Password: --------------------------------------------- </textarea> <br> </form> <form name="myForm" method ="post" action="index2.php?saving=1" onsubmit="return validateForm();"> <tr> <td align="right" width="10%"> Email: </td> <td><input type="text" name="email" id="email" size ="40" /> </td> </tr> <input type="submit" value="Submit"> </form> <p> <a href="index.html">Home</a> </html> PHP CODE: Code: [Select] <?php $saving = $_REQUEST['saving']; if ($saving == 1){ $data = $_POST['data']; $file = "data.txt"; $fp = fopen($file, "a") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> Hi guys... i want to do registration of text box which are created dynamically.. please help me how can i do registration? I found a little javascipt online, and I wanted to play around with it. I'm trying to add a little php to it, I think I'm close to getting it, but when I click on the properties of the pictures that I want displayed, it has a bunch of extra garbage in it. So is the javascript reading something extra in the php script ? Here is the code. Code: [Select] <script language="JavaScript"> var j,d="",l="",m="",p="",q="",z="",KW_ARI= new Array() KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; j=parseInt(Math.random()*KW_ARI.length); j=(isNaN(j))?0:j; document.write("<img name='seqSlideShow' src='"+KW_ARI[j]+"'>"); function seqSlideShow(t,l) { x=document.seqSlideShow; j=l; j++; if (j==KW_ARI.length) j=0; x.src=KW_ARI[j]; setTimeout("seqSlideShow("+t+","+j+")",t); } seqSlideShow(10000,0) </script> well i got more questions since i started at javascript and now im currently practicing php my question is whats the equivalent of this lines of codes to php language? document.getElementById("txt1").value <input type="button" name="one" id="one" value="1" onclick="javascript:getvalue(1);"\> == well what i mean is can i pass value to php functions every time i click it? just like calculators OT: can some1 help me translating my js calcu codes to php ones? document.getElementById("txt1").value this is my main problem i cant display the buttons i click so I am not the best coder, and have been having a really hard time getting this devision in javascript. I would put it in html, but I use javascript to clear the page
<div id="test" style='position:fixed;bottom:0;left:0; height:76;background:darkorange;width:100%;'><h><object width="75" onclick="web()" height="75" data="img1.jpg"></object> <object width="75" onclick="mdoge()" height="75" data="img2.jpg"></object> <object width="75" onclick="word()" height="75" data="img3.jpg"></object></h></div>so that code above is the code I need to put in a document.write of something of equivalence. Is there any way to put this in javascript? thank you Hello, I'm currently working on a gaming website, however there is an issue. I have a custom YouTube player, however I need to get the link dependant on a value from the database. The ID is in the URL, which is then collecting the youtube video URL from the database. However, I'm trying to then echo that back out into the Javascript video. On my normal page, that plays the Video is: Header: Styles.css & youTubeEmbed-jquery-1.0.css need to be added. Code: [Select] <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Having Fun With YouTube's API - Making a Custom Video Player | Tutorialzine Demo</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <link rel="stylesheet" type="text/css" href="video_player/youTubeEmbed/youTubeEmbed-jquery-1.0.css" /> </head> Footer: All of that needs to be added. Code: [Select] <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script src="jquery.swfobject.1-1-1.min.js"></script> <script src="youTubeEmbed/youTubeEmbed-jquery-1.0.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#player').youTubeEmbed("VID LINK FROM DB SHOULD BE HERE"); $('form').submit(function(){ $('#player').youTubeEmbed({ video : 'VID LINK FROM DB SHOULD BE HERE', width : 640, // Height is calculated automatically progressBar : false // Hide the progress bar }); }); }); </script> </body> </html> Code: [Select] <?php include("config.php"); $host = $config['Site']['Host']; $username = $config['Site']['Username']; $password = $config['Site']['Password']; $database = $config['Site']['Database']; $name = $config['Site']['Name']; $favicon = $config['Site']['Favicon']; mysql_connect($host, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); function getVid() { $vID = $_GET['vID']; $sQuery = "SELECT * FROM vids WHERE id='$vID'"; $sResult = mysql_query($sQuery); while($row = mysql_fetch_array($sResult)) { $vID = $row['url']; } } ?> Above is the Global.php, and that's where the problem lies, whenever I try to insert the peices required, nothing happens and the video doesn't show. Could anybody please help?! <html> <head> <script type=\"text/javascript\" src=\"swfobject.js\"></script> </head> <body> <script type=\"text/javascript\"> var multiplayer = new SWFObject(\"player.swf?xml=config.xml&player_skin=skin.swf\", \"multiVideoPlayer\", \"361\", \"283\", \"7\", \"#FFFFFF\", true); multiplayer.write(\"flashcontent\"); </script> </body> </html>Hi, Could anyone help make the above code run inside my PHP file? When loaded, I just get a blank page and I know the paths to files are correct. Thank you Edited by hexcode, 11 July 2014 - 01:19 PM. Hello all, i need your help on this.
I don´t know if it´s possible, and if possible, i don´t know how to do it.
I catch visitors country code using javascript in a variable called "country".
Then, i need to php include diferent files based on that country code, like:
if country == UK
include header_uk.php
else if country == US
include header_us.php
else if country == BR
include header_br.php
else
include header.php
I don´t know nothing about coding, this is just an example.
I don´t have another way of catching visitors country without javascript.
Is this possible?
Thanks in advance.
Edited by vascorama, 17 August 2014 - 01:49 PM. I need some help. I'm having trouble calling a javascript function from a php script Code: [Select] <?php include ('security.inc'); include ('head.inc'); echo ' <table class="menutable"> <tr> <td nowrap> <div id="sidemenu" style="display:block;"> <ul id="navbar">'; // database-driven menu groups // get the menu items and groups that this user has access to if (!isset($_SESSION['usergroupsin']) || $_SESSION['usergroupsin']==''){ $menurs=array(); } else { $sql="SELECT mg_name, mg_desc, mi_name, mi_desc, mi_link, mi_external_link, mgg_gr_id, mig_gr_id FROM tbl_menu_items INNER JOIN tbl_menu_groups ON mi_mg_id=mg_id AND mg_active='y' LEFT JOIN tbl_menu_groups_groups ON mgg_mg_id=mg_id AND mgg_active='y' LEFT JOIN tbl_menu_items_groups ON mig_mi_id=mi_id AND mig_active='y' WHERE ( mgg_gr_id IN (".$_SESSION['usergroupsin'].") OR mig_gr_id IN (".$_SESSION['usergroupsin'].") OR mi_secure='n' ) AND mi_active='y' AND mg_left_menu='y' GROUP BY mg_name, mg_desc, mi_name, mi_desc, mi_link, mi_external_link ORDER BY mg_sort, mi_sort"; $menurs=myload($sql); } $last_mg_name=''; if (count($menurs)>0){ foreach ($menurs as $m){ // show the group heading if we haven't already shown it if ($m['mg_name']<>$last_mg_name){ echo '<li><strong> <br>'.$m['mg_name'].'</strong></li>'; $last_mg_name=$m['mg_name']; } // determine whether this is a system link or not if ($m['mi_external_link']=='y'){ $thisurl=$m['mi_link']; } else { $thisurl=$config['system_url_root'].$m['mi_link']; } echo '<li><a title="'.$m['mi_desc'].'" href="'.$thisurl.'"><strong> - '.$m ['mi_name'].'</strong></a></li>'; } } echo ' </ul> </div> </td> [b]<input class="button" type="button" value="Hide Menu" onclick="setTable('sidemenu');return true">[/b] <td width="100%"> <div id="mainwindow"> <!-- BEGIN PAGE CONTENT --> '; ?> My javacscipt function is in the head.inc. I can post that if needed. The bolded part is what I'm having trouble with. Specifically, the onclick. Without that, my script works, if I have the onclick in there, I get a blank page. I'm trying to hide/show the div=sidemenu. If anybody has any suggestions, I'm open to it. I would like to put an ad delay onto a webpage. No content shows up (complete white backgorund) until 30 seconds after viewing the ad. The ad would disappear and the content of the page would load up.
|