PHP - Javascript Parameter Passing In Php Script
Hello,
I have below javascript, which I need to put in a new php page. However I need the vistiors to pass in the username to the script either by clicking the link for that user or by entering a value on the website. I am not sure how can I do this in php script and modify below java script to make it work. Any help will be greatly appreciated. <pre class="example"> $(function(){ $(".tweet").tweet({ join_text: "auto", username: "NEED_TO_BE_PARAMETER", avatar_size: 68, count: 25, auto_join_text_default: "said,", auto_join_text_ed: "I", auto_join_text_ing: "I wase", auto_join_text_reply: "I replied", auto_join_text_url: "I was checking out", loading_text: "loading..." }); }); </pre> <div class='query'></div> <script type="text/javascript"> $(function(){ $(".example").each(function(i, e){ eval($(e).text()); }); }); </script> Similar TutorialsHello all, I'm an absolute Newbie to PHP. I'm struggling with a problem that I think is extremely basic to you experts but I just can't get it to work. In short, I have an application that has a link that goes to: Site1/dir/admin?id=(text)&page=(number) I want to redirect to a link that's identical except it's Site2 at the beginning instead of Site 1. What I've attempted so far is this: <?php $GLOBALS[$passid]=$_GET['id']; $GLOBALS[$passpage]=$_GET['page']; header( 'Location: http://site2.com/dir/admin/?page=$passpage&id=$passid'); ?> But it just redirects to http://site2.com/dir/admin/?page=$passpage&id=$passid (with all of that text being literally what is in the URL, not the variable values) I have a feeling I'm doing something small but very basic wrong. The $GLOBALS thing was an afterthought. Outcome is the same with or without that. Any help much appreciated!!! hello this is my first time posting so i'm sorry if i word this wrong or it is a stupid question. i have a simple database made up with a product table with five fields; id, url, name, description, and price. also a categories table with five fields; id, parent_id, siteurl, name, and description. i have everything up and running,but i can't figure out how to pass the product id as a parameter. right now i have "example.php" but i need "example.php?id=1" here is what my code looks like indextest.php Code: [Select] <?php error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Car Dealer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $usr = "root"; $pwd = ""; $db = "mymarket"; $host = "localhost"; //connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } $category = ""; // setup SQL statement $SQL = " SELECT * FROM categories "; $SQL = $SQL . " WHERE parent_id = '0' "; // execute SQL statement $retid = mysql_db_query($db, $SQL, $cid); // check for errors if (!$retid) { echo( mysql_error()); } else { ?> <div id="layout"> <div id="titlebg"> <div class="title">CAR</div> <div class="title1">DEALER</div> <div class="title2">WE HAVE</div> <div class="title3">THE BEST CARS</div> <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div> </div> <hr id="hrline" /> <div id="gradientbg"> <div id="links"> <h2> <?php // display results echo ("<p><dt><b>$category</b><br>\n"); while ($row = mysql_fetch_array($retid)) { $siteurl = $row["siteurl"]; $name = $row["name"]; echo ("<dd><a href='$siteurl'>$name</a></dd>\n<br>"); } echo ("</dt></p>"); } ?> <h2/> </div> <div id="header"></div> </div> <div id="bodypart"> <div id="catalogue"> <div class="cat">CATALOGUE</div> <div id="cat1"></div> <div id="car1"></div> <div id="cat2"></div> <div id="car2"></div> </div> <div id="line"></div> <div id="ourservices"> <div class="our">OUR SERVICES</div> <div id="pic1"></div> <div class="lorem">Lorem ipsum</div> <div class="txt">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div> </div> <div id="line1"></div> <div id="aboutus"> <div class="abt">ABOUT US</div> <div id="pic2"></div> <div class="lorem1">Lorem ipsum</div> <div class="txt1">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div> </div> </div> <hr id="hrline1" /> <div class="foottxt">Copyright © Cars. Design by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>.</div> </div> </body> </html> and i would like to link that to this next file att.php Code: [Select] <?php error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Smartphone Dealer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $usr = "root"; $pwd = ""; $db = "mymarket"; $host = "localhost"; //connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } $category = ""; // setup SQL statement $SQL = " SELECT * FROM categories "; $SQL = $SQL . " WHERE id ='4' OR id = '5' OR id = '6' "; ?> <div id="layout"> <div id="titlebg"> <div class="title">SMARTPHONE</div><br> <div class="title1">DEALER</div> <div class="title2">WE HAVE</div> <div class="title3">NO CONTRACT SMARTPHONES</div> <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div> </div> <hr id="hrline" /> <div id="gradientbg"> <h3> <?php // execute SQL statement $retid = mysql_db_query($db, $SQL, $cid); // check for errors if (!$retid) { echo( mysql_error()); } else { // display results echo ("<p><dt><b>$category</b><br>\n"); while ($row = mysql_fetch_array($retid)) { $siteurl = $row["siteurl"]; $description = $row["description"]; echo ("<dd><a href='$siteurl'>$description</a></dd>\n<br>"); } echo ("</dt></p>"); } ?> </div> <h3> </div> <hr id="hrline1" /> <div class="foottxt">Copyright © Nathan Hein. Template by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>. <br> DISCLAIMER: This website was designed for a school project and is not intended for commercial use of any kind.</div> </div> </body> </html> i know i probably have a lot of problems with this code, but the one i can't figure out is passing the parameter and i have been looking at forums, websites, w3schools, everywhere. i;m just not grasping the concept of how to make it work with this. thank you so much for any input Hello All Can someone help me with this: I am trying to create some PHP code to pass 2 variables to a stored procedure. At the moment I have: <?php // Connect to MSSQL and select the database $serverName = "(local)"; $connectionInfo = array( "Database"=>"ashley"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } /*Call the stored procedure with a named parameter*/ $tsql = 'EXEC CPS_ADD_NEW_USER @agentF = php,@agentS=test'; $stmt = sqlsrv_query($conn, $tsql); /* Free statement and connection resources. */ sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?> Could anyone advise me what I need to be doing and where I am going wrong Thanks in advance Bicky I am experimenting around with PDO, I have a DB handle class and instancing it in a function. The problem is when I want to bind elements in a query, for example I bind a parameter but I can only do it using a varible outside of the object. Code: [Select] <?php $database = new Database("localhost", "fry", "root", ""); $database->set_table("usertest"); $database->set_query("SELECT * FROM usertest WHERE user_name = :user_name"); $value = "matt"; $database->prepare_query(); $database->bind("parameter", ":user_name", $value ,PDO::PARAM_STR, 5); $database->execute(); while($result = $database->fetch()) { echo $result['user_name'].'<br />'; } ?> Is this bad OOP practice? I wanted to put $value = "matt"; into the Database class somehow here is the Database class Code: [Select] <?php class Database{ public $hostname; public $database; public $username; public $password; public $connection; public $prepare; public $query; public $table; public $fetch; public $bind_var; public $bind_val; function __construct($hostname, $database, $username, $password) { $this->hostname = $hostname; $this->database = $database; $this->username = $username; $this->password = $password; $this->Database_connection(); } public function Database_connection() { try { $this->connection = new PDO('mysql:host='.$this->hostname.';dbname='.$this->database, $this->username, $this->password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } public function set_query($query) { $this->query = $query; } public function get_query() { return $this->query; } public function set_table($table) { $this->table = $table; } public function get_table() { return $this->table; } public function set_bind_var($var) { $bind_var = $var; } public function set_bind_val($val) { $bind_val = $val; } public function get_bind_var() { return $this->bind_var; } public function get_bind_val() { return $this->bind_val; } public function bind($bindtype, $val, $var, $pdo, $num) { if ($bindtype == "parameter") { $result = $this->prepare->bindParam($val,$var,$pdo); } return $result; } public function prepare_query() { $this->prepare = $this->connection->prepare($this->get_query()); } public function execute() { $this->prepare->execute(); } public function fetch() { return $this->prepare->fetch(); } } ?> Yet agian sorry for the sloppy code, this is mainly an experiment, would be very appriciated if someone could help me out with this problem. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=351532.0 I have the following code just to insert a username and hashed password into the database but somehow I am getting this error and I couldn't find out where I am doing it wrong...can someone please give me a hand?
I tried it in two ways and both errors...
the first few lines are just connecting database which worked fine and a password.php so I can use password_hash() with my php version
$hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $username = 'xx'; $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES (:username, :hash) "); $insertQuery->execute(array( 'username' => $username, 'password' => $hash ));also tried $hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES ('xx', :hash) "); $insertQuery->execute(array( 'username' => 'xx', 'password' => $hash )); Hello,
I recently posted here about an issue I was having with my database orientated products page.
I have now run into another problem where say if, /db.php was typed or /db.php?p=IDoNotExist was typed, it returns blank.
I have in my code the desired content to be displayed, but it just doesn't seem to want to make a show.
I was also wondering if it is possible to show different content for whatever the URL is, so for no parameter, the content about the products, and a non existent one, maybe "Product not found"?
Here is my code:
<?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); $status = htmlspecialchars( @$_GET ['p'] ); if ($status == "floorpuzzles") { echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?p=$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } ?> <? }else{ if ($status == $_GET["p"]) { $sql="SELECT ID, Name, Tags, Description, Pieces, Size, Barcode, Category FROM products WHERE ID = '" . $_GET['p'] . "'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode: $Barcode</p>"; echo "</div>"; } }else{ ?> <? echo"<h1>Our Products</h1> <p>Our jigsaw puzzles are hand cut by skilled craftsmen and therefore each one is unique with self-correcting pieces. There is a strict quality control process at all stages by our highly experienced staff. The puzzles are durable and provide fun and excitement, enhancing learning and a child’s development.<p> <p>All of our jigsaws are made using materials from sustainable resources grown in managed forests. Where possible we support companies in the UK and source our components locally, most of our suppliers are in the East Midlands, many in Derbyshire and Nottinghamshire. We keep packaging to a minimum and take our environmental and ethical responsibilities very seriously.</p> <p>Reducing waste and recycling was a way of life for us before it became fashionable. We are constantly searching for new ideas and consult teachers when developing our jigsaws, which are often used within the national curriculum.</p> <p>As well as making our own range, we manufacture for leading suppliers to the education market. Check for \"Made in Britain\" and it is probably made by us.</p> <p>We have a wide variety of products available for viewing, from classic floor puzzles to innovative inset trays. You can take a look at all our products on this page, simply use the navigation buttons to your left.</p>"; }} include("footer.php"); ?>The final echo is what I wish to be displayed on the URL without or with an invalid parameter. Here is my site URL: http://www.webwib.co...saws/search.php (note that only the "Floor Puzzles" category has content within it). Thank you in advance for assistance. I have a html for that posts to a form processing script which is fully functional atm, in the processing script i have if statements, if the condition is met it updates tables in database, if there not met i echo a "not met" statment. problem is my form processing script just goes straight back to the index.php page using the following code; header('Location: index.php'); here is the form processing script: <?php session_start(); header('Location: index.php'); include "connect.php"; $id = $_SESSION['id']; $user = $_SESSION['user']; $ticketNumber = $_POST[ticketNumber]; //echo $_POST[ticketNumber]; $today = date('Y-m-d H:i:s', time() - 3600); // Query "Ticket" Table to check if user has purchased a "regular" ticket within the last 24 hours $query24hour = mysql_query("SELECT * FROM tickets WHERE username = '$user' AND HOUR(TIMEDIFF(NOW() , purchaseDate)) < 24;") or die(mysql_error()); // Query "promoTickets" table to grab information of previous tickets bought to the "promotional" auction and LIMIT tickets to 1 per user for "promotional" auctions. $querySold = mysql_query("SELECT * FROM promoTickets WHERE promoID='$_POST[promoID]' AND (ticketNumber='$ticketNumber' OR username = '$user');") or die(mysql_error()); //echo $querySold; $sold = mysql_fetch_assoc($querySold); //print_r($sold); //echo $sold; //echo query24hour; $querycount24hour = mysql_num_rows($query24hour); //echo $querycount24hour; //check if ticket is sold and if user has purchased a "regular" ticket within 24 hours if(empty($sold)!=FALSE and $querycount24hour >= 1){ //Checks users balance to see if they have enough for the ticket $queryBal = mysql_query("SELECT user_iskbalance FROM users WHERE username = '$user';") or die(mysql_error()); //echo $querySold; //echo $user; //echo $queryBal; $balArray = mysql_fetch_assoc($queryBal); $bal = $balArray[user_iskbalance]; $newBal = $bal-$_POST[ticketPrice]; //check if he has the money to buy the ticket if($bal>=$_POST[ticketPrice]){ //remove the money $queryBalRemoveal = mysql_query("UPDATE `users` SET `user_iskbalance`='$newBal' WHERE `username`='$user';") or die(mysql_error()); //buy ticket & insert data into "promoTickets" table $query = mysql_query("INSERT INTO promoTickets(promoID, username, charID, ticketNumber, ticketPrice, purchaseDate) VALUES ('$_POST[promoID]', '$user', '$id', '$_POST[ticketNumber]', '$_POST[ticketPrice]', '$today');") or die(mysql_error()); } else{ die("Insufficent balance. Please add more ISK") ; } } else{ die("Ticket has already been Sold or you have already bought a ticket to this promotion..!"); } ?> any way i can get the errors to be passed onto the index.php (with the form) and echo them there? as it stands errors arnt shown to the users and its confusing people Hi
I am trying to create a google chart from data in query.php and using the google api to load it. Everything works until I want to change the MetalSourceID from a drop select box.
PHP CODE FOR DROP DOWN BOX:
<form> <select name="users" onchange="showUser(this.value);drawChart();"> <option value=""> Select a Metal: </option> <?php $query = "SELECT TOP(31) tblMetalPrice.MetalSourceID, tblMetalSource.MetalSourceName from tblMetalPrice INNER JOIN tblMetalSource ON tblMetalPrice.MetalSourceID=tblMetalSource.MetalSourceID ORDER BY tblMetalPrice.DateCreated DESC "; $result = sqlsrv_query( $conn, $query); while( $row = sqlsrv_fetch_object ($result)) { echo "<option value='".$row->MetalSourceID ."'>". $row->MetalSourceName ."</option>"; } sqlsrv_close( $conn); ?> </select> </form>This works fine and generates all the correct values. One part of this changes contents of a table which works fine. But I also echo the MetalSourceID into the javascript for the google api, JS script below: <script type="text/javascript"> google.load('visualization', '1', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var jsonData = $.ajax({ url: "query.php", dataType:"json", async: false, data: { 'MetalSourceID' : <?php $q = intval($_GET['q']); echo $q; ?> } }).responseText; var data = new google.visualization.DataTable(jsonData); var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data); } </script>This then runs the query.php script and returns the google line chart, a copy of the query.php script is below: I have a php string variable that is created by php code within an html form ($answer). I need to pass this string variable along with all the html form input data to another php script specified with the form "action" (post method). All the html form input data is coming thru fine but not the variable ($answer). How do I do this? Here is the php code for importing html form data at the script called in the form action: $languages = $_POST['languages']; $answergiven = $_POST['answergiven']; $problemanswer = $_POST['$answer']; 'languages' and 'answergiven' are form inputs and come thru fine. '$answer' does not get passed to the second script. How do I do this? Here is the php code within the first html form <?php // OPEN DATABASE $username="servics3_sample"; $password="sample"; $database="servics3_sample"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // GENERATE RANDOM PROBLEM NUMBER $probnum = (rand ( 1 , 9 )); echo $probnum; // RETRIEVE ANTI-SPAM PROBLEM $query="SELECT * FROM liasantispam WHERE `problem number` LIKE '%$probnum%' "; $result=mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); $firstnum=mysql_result($result,0,"first number"); $operator=mysql_result($result,0,"operator"); $secondnum=mysql_result($result,0,"second number"); $answer=mysql_result($result,0,"answer"); echo $firstnum," ",$operator," ",$secondnum," = "; mysql_close(); ?> Hi I am trying to pass a csv file into a powershell script and then return the output and display it to the user. The file is a firewall checker. Any advice or solutions on where I am going wrong would be most appreciative, Thanks.
<?php 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... This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=355358.0 Hello Everyone! I have created a javascript array which now i want to pass to php, so php can store those values to mysql. So please anyone can suggest me how do i pass it to php? Any help will highly be appreciated! 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 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); Hello, I'm first time posting here, my PHP Javascript and HTML level is "trial, error, google", I've done some scripts, but now I'm facing one problem. Here's a code example: <?php $sa = array("Text without quotes.", "Text with 'quotes'.", "Text with \"Double Quotes\".", "Text With \"BOTH' kind of quotes."); echo "<A HREF='javascript:void(alert('".htmlspecialchars($sa[0], ENT_QUOTES)."'))'>Test One</A><BR/>"; echo "<A HREF='javascript:void(alert('".htmlspecialchars($sa[1], ENT_QUOTES)."'))'>Test Two</A><BR/>"; echo "<A HREF='javascript:void(alert('".htmlspecialchars($sa[2], ENT_QUOTES)."'))'>Test Three</A><BR/>"; echo "<A HREF='javascript:void(alert('".htmlspecialchars($sa[3], ENT_QUOTES)."'))'>Test Four</A><BR/>"; ?> What I'm trying to do is pass array of strings with quotes in them to my javascript, I tried using addslashes, htmlspecialchars but none of them work correctly. Whats the Right way to pass a string how do I preprocess it so javascript understands it correctly? Sorry if it's very simple or common question, I must have missed it in FAQ section. Thank you. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=348942.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=332103.0 |