I'm trying to concatenate a link in a javascript function with a php variable. But whatever a try to write after ""+ doesn't get displayed and the whole program stops working.  The variable is defined in a different page. I tried REQUEST to access to it, but it's not working.  function popupEvent(){     $('#btnClose').unbind("click");      $('#btnClose').click(function(){     window.location = SITEURL+"cart/rollPdf/?POrderNo="+implode(',', $orderIDArr);    window.open(ord,'winname','directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=350');                       return false     }); }
8481
What is the easiest way to encode a PHP string for output to a JavaScript variable?  I have a PHP string which includes quotes and newlines.  I need the contents of this string to be put into a JavaScript variable.  Normally, I would just construct my JavaScript in a PHP file, à la:  &lt;script&gt;   var myvar = "&lt;?php echo $myVarValue;?&gt;"; &lt;/script&gt;   However, this doesn't work when $myVarValue contains quotes or newlines.
6080
I'm new to both JavaScript and . In YUI library examples, you can find many uses of this construct:  (function() {     var Dom = YAHOO.util.Dom,     Event = YAHOO.util.Event,     layout = null,         ... })();   I think the last couple of parentheses are to execute the function just after the declaration.  ... But what about the previous set of parentheses surrounding the function declaration?  I think it is a matter of scope; that's to hide inside variables to outside functions and possibly global objects. Is it? More generally, what are the mechanics of those parentheses?
111870
I often use ($var &amp; 1) in my code, which returns true if $var is an odd number and false if it's an even number.  But what does "&amp;" actually do?
82255
I'm making a page which has some interaction provided by javascript. Just as an example: links which send an AJAX request to get the content of articles and then display that data in a div. Obviously in this example, I need each link to store an extra bit of information: the id of the article. The way I've been handling it in case was to put that information in the href link this:  &lt;a class="article" href="#5"&gt;   I then use jQuery to find the a.article elements and attach the appropriate event handler. (don't get too hung up on the usability or semantics here, it's just an example)  Anyway, this method works, but it  a bit, and isn't extensible at all (what happens if the click function has more than one parameter? what if some of those parameters are optional?)  The immediately obvious answer was to use attributes on the element. I mean, that's what they're for, right? (Kind of).  &lt;a articleid="5" href="link/for/non-js-users.html"&gt;   In  I asked if this method was valid, and it turns out that short of defining my own DTD (I don't), then no, it's not valid or reliable. A common response was to put the data into the class attribute (though that might have been because of my poorly-chosen example), but to me, this smells even more. Yes it's technically valid, but it's not a great solution.  Another method I'd used in the past was to actually generate some JS and insert it into the page in a &lt;script&gt; tag, creating a struct which would associate with the object.  var myData = {     link0 : {         articleId : 5,         target : '#showMessage'         // etc...     },     link1 : {         articleId : 13     } };  &lt;a href="..." id="link0"&gt;   But this can be a real pain in butt to maintain and is generally just very messy.  So, to get to the question, how do you store arbitrary pieces of information for HTML tags?
12917
I would like to use variable substitution on a particular string that I access via a command. For example, if I copy something into my clipboard, I can access it like this.  $ xclip -o -selection clipboard Here's a string I just copied.   If I assign it to a variable, then I can do variable substitution on it.  $ var=$(xclip -o -selection clipboard) $ echo $var Here's a string I just copied. $ echo ${var/copi/knott} Here's a string I just knotted.   However, is there a way to do variable substitution without assigning it to a variable? Conceptually, something like this.  $ echo ${$(xclip -o -selection clipboard)/copi/knott} bash: ${$(xclip -o -selection clipboard)/copi/knott}: bad substitution   This syntax fails, because var should be a variable name, not a string.
62865
In PHP, the HEREDOC string declarations are really useful for outputting a block of html.  You can have it parse in variables just by prefixing them with $, but for more complicated syntax (like $var[2][3]), you have to put your expression inside {} braces.  In PHP 5, it is possible to actually make function calls within {} braces inside a HEREDOC string, but you have to go through a bit of work.  The function name itself has to be stored in a variable, and you have to call it like it is a dynamically-named function.  For example:  $fn = 'testfunction'; function testfunction() { return 'ok'; } $string = &lt;&lt;&lt; heredoc plain text and now a function: {$fn()} heredoc;   As you can see, this is a bit more messy than just:  $string = &lt;&lt;&lt; heredoc plain text and now a function: {testfunction()} heredoc;   There are other ways besides the first code example, such as breaking out of the HEREDOC to call the function, or reversing the issue and doing something like:  ?&gt; &lt;!-- directly output html and only breaking into php for the function --&gt; plain text and now a function: &lt;?PHP print testfunction(); ?&gt;   The latter has the disadvantage that the output is directly put into the output stream (unless I'm using output buffering), which might not be what I want.  So, the essence of my question is: is there a more elegant way to approach this?  Edit based on responses: It certainly does seem like some kind of template engine would make my life much easier, but it would require me basically invert my usual PHP style.  Not that that's a bad thing, but it explains my inertia..  I'm up for figuring out ways to make life easier though, so I'm looking into templates now.
33938
I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?  Here is an example script that does not work on my hosts' server as of right now:  &lt;?php session_start(); if(isset($_SESSION['views']))     $_SESSION['views'] = $_SESSION['views']+ 1; else     $_SESSION['views'] = 1;  echo "views = ". $_SESSION['views']; echo '&lt;p&gt;&lt;a href="page1.php"&gt;Refresh&lt;/a&gt;&lt;/p&gt;'; ?&gt;   The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a  problem on their side, but I wanted to make sure I'm not a complete idiot first.  Here is the phpinfo() for my hosts' server (PHP Version 4.4.7):
46438
when i select the records in vf page ,after click on the VF Button the conga should be call along with id for generating the PDF but on button click the window is opening but showing error that "ID Parameter is missing" ? how to over come the issue? your reply will be appricated ,please reply asap.  vfpage:  &lt;apex:commandButton value="Generate Invoice" action="{!GenerateInvoice}"  onclick="openConga(setOfIds)" reRender="table1"/&gt;  &lt;script&gt; function openConga(setOfIds){   if(setOfIds !=Null){   var Formastring=setOfIds.splits(',');   var joinIds=Formastring.join("'|'");   var removeSpace=joinIds.replace(" ","");   var removeLeft=removeSpace.replace("[","");   var removeRight=removeLeft.replace("]","");   var finalSetIds=removeRight;    var CongaUrl ="/apex/APXTConga4__Conga_Composer?sessionId={!$API.Session_ID}" +"&amp;serverUrl={!$API.Partner_Server_URL_290}&amp;Id={!Payment_Id}" +"&amp;QVar1Id=[sql1221]a186C0000007yB3?pv1=" + finalSetIds +"&amp;TemplateId={QVar1}";  window.open(CongaUrl, "Conga","menubar=no,height=600,width=800");    } } &lt;/script&gt;   controller:  [‎28-‎01-‎2019 12:13]  Sakhare, Ankita:   public PageReference GenerateInvoice() {     selectedEsr = new List &lt; Payment__c &gt; ();     for (wrappayment wp: paymentList) {         if (wp.selected == true) {             Payment_Id = wp.pay.id;          }     }      return null; }
53497
Is it possible to call a function from PHP using onsubmit from JavaScript? If so could someone give me an example of how it would be done?  function addOrder(){     $con = mysql_connect("localhost", "146687", "password");     if(!$con){         die('Could not connect: ' . mysql_error())     }      $sql = "INSERT INTO orders ((user, 1st row, 2nd row, 3rd row, 4th row)     VALUES ($session-&gt;username,1st variable, 2nd variable, 3rd variable, 4th variable))";      mysql_query($sql,$con)     if(mysql_query($sql,$con)){         echo "Your order has been added";     }else{         echo "There was an error adding your order to the databse: " . mysql_error();     } }   That's the function I am wanting to call. Its an ordering system, you type in how much of each item you want, hit submit and it should add the order to the table.
10610
I have a url like   I need a javascript function to give me the 'th' value from that.  All my urls have the same format (2 letter filenames, with .html extension).  I want it to be a safe function, so if someone passes in an empty url it doesn't break.  I know how to check for length, but I should be checking for null to right?
19928
How can I exit the JavaScript script much like PHP's exit or die? I know it's not the best programming practice but I need to.
121447
I'm using a little plugin that allows me to add source link to every article. I found the code in this thread:   It's almost perfect, but I need to make 2 little modifications:   When there's no source link, the word "Source:" is still showing up (here's how it looks like: ), but I need to get rid of it if no source link is added. Does anyone have any idea how to do it? Source link shows on every page of a post. I have some posts splitted into multiple pages, but the link still shows on each one of them. I need to change this - the link has to show up only on the last page of a splitted post. Any ideas how to achieve that?   Here's the code I'm using (pasted in functions.php):  - the first one  And here's what I have in my single.php (single post):   &lt;div class="source-link"&gt;Source: &lt;?php echo esc_url( get_post_meta( $post-&gt;ID, '_source_link', true ) ); ?&gt;&lt;/div&gt;   Thanks in advance. Im desperate for help.  Kacper
4059
The situation is somewhat like-  var someVar = some_other_function(); someObj.addEventListener("click", function(){     some_function(someVar); }, false);   The problem is that the value of someVar is not visible inside the listener function of the addEventListener, where it is probably being treated as a new variable.
111204
I have three strings:  $str1 = "abc"; $str2 = "def"; $str3 = "ghi";  I can get the value of all of them like this:  echo "$str1$str2$str3";  But I heard there is a way to join them together, so I can echo all of them without quotes.
30377
AFAIK, you never need to specify the protocol in an onclick:  onclick="javascript:myFunction()" Bad  onclick="myFunction()" Good  Today I noticed in  on Google Anallytics that they are using it:  &lt;a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');"&gt;   Is this example just plain wrong, or is there ever a reason to specify javascript: in anything other than a href?
75774
I have been frequently using concatenate to combine cells and strings to render URLs in cells. The purpose of these URLs is to open specific pages to review the information on those pages.  I am looking to create a comma separated (or other) list in one cell where I can open all of the links in separate tabs (especially if it can be in a new window).  Is there a way of using something like target="_blank to make Sheets open those links? Would it only be possible using the script editor somehow?
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.