How to add ' to generated link in php - javascript

$output .= '<a class="dropdown-toggle has-category" data-toggle="dropdown" href="'.$this->getLink($menu).'" target="'.$menu['target'].'">';
I have php file with this code href="'.$this->getLink($menu).'"
its generates in html this href="https://www.myweb.com/"
Now i need to do it with onClick so that the output turned out like this
onclick="location.href='https://www.myweb.com'"
Changed php code onclick="location.href='.$this->getLink($menu).'"
and result is onclick="location.href=https://www.myweb.com"
Link not working cuz lacks '
Can someone help me?

Try this
onclick="location.href=\''.$this->getLink($menu).'\'">
Example:-
echo '<a onclick="location.href=\''.$this->getLink($menu).'\'">';

Can you add this escaped single quote: \'?
echo '...onclick="location.href='.$this->getLink($menu).'\'"...';
(I added the echo to complete the code example).

Related

including html tag in a php code, specifically dealing with href function inside a php block

enter the html code once a condition is satisfied but then i aim to use php values and html tags together.
tried tag etc and got most of the part in running just unable to deal with href beacuse it is referencing to some values.
not sure where to use "" or ``.
<?php.....
echo `Yes`;
?>
"yes" should work as a hyperlink but at the moment the php values are not processed that`s why no result.
You are using wrong sequence of quote
<?php
...
?>
<?php
echo '<a href="limitdatabase.php?Dropdown=' .
$_GET['Dropdown'].
';&search='.
$search_name .
';&wise='.
$_GET['wise'].
';">Yes</a>';
?>
and you should use single quote and not backtics for string
You are using incorrect concatenation. Whenever you want to add any PHP variable then you need to close the braces and need to start after PHP variable as below:
<?php
echo 'Yes';
?>
Also you should wrap Dropdown and wise in braces as it will not work directly in get as you have used. Hope it helps you!
You can use combination of html with php inside:
<a href="limitdatabase.php?Dropdown=<?PHP echo $_GET[Dropdown] . "&search="
. $search_name . "&wise=" . $_GET[wise]; ?>">Yes</a>
Also, you can input whole link in string:
<?php
$mylink = "limitdatabase.php?Dropdown=" . $_GET[Dropdown] . "&search=" . $search_name . "&wise=" . $_GET[wise];
?>
YES

PHP a href echo with span not functioning properly

I have the code
echo '<span class="imperial-username">';
echo'<a target="_blank" href="profile/'.$row['name'].'">'.$row['name'];'</a>';
echo'</span>';
which functions fine when i press the name it takes me to the profile. But if I click the image also above the name it will go to the person who is above on the list, as I have a list of links. And only goes to there profile if you click the name specifically.
Also all other links on the page seem to be not functioning properly and going to random profiles when pressed, the links are carrying over down the page or something is what I assume, maybe code not closed properly, but I see nothing that should be causing this.
You have a semicolon ; instead of a dot . in .$row['name'];'</a>';.
It is not a syntax error, because the instruction '</a>'; is valid but has just no effect.
please try this
echo '<span class="imperial-username">';
echo'<a target="_blank" href="profile/'.$row["name"]>'.$row["name"].'</a>';
echo'</span>';
echo '<span class="imperial-username">';
echo '<a target="_blank" href="profile/'.$row['name'].'">'.$row['name'].'</a>';
echo '</span>';

TinyMCE exec Command inside php loop

Trying to get an href with TinyMCE command function working but no luck. I used double and single quotes as well. Here is the original code
echo "<a href="javascript:;" onclick="tinyMCE.activeEditor.setContent('');tinymce.execCommand('mceInsertContent',false, document.getElementById('div_".$i."').innerHTML);
return false;">[Manage Marketing]</a>";
echo "<a href=\"javascript:;\" onclick=\"tinyMCE.activeEditor.setContent('');tinymce.execCommand('mceInsertContent',false, document.getElementById('div_".$i."').innerHTML);
return false;\">[Manage Marketing]</a>";

Write onclick method that has parameters in php print function

I'm having problems with writing an onclick method in php print in code below:
<?php print "<p><small> <a href='#' onclick='ajaxMenu('comments.php?news=".$fileContent['id']."');>".$number. " ".$text." </small> </a> </p>"; ?>
Given code doesn't work. I believe it's because of combination of single and double quotes in it. Can anyone help me to solve this?
You can escape " characters by having a forward slash \"
<?php echo( "This is a link" ); ?>

PHP link written into page not being retrieved by a JAVASCRIPT function

I'm writing on a page the following code with PHP. This code creates a A HREF link with the ID equal to $intIdType, which is the value of the PRIMARY KEY in a database, and $count gets the amount of records per category on the database. All of this is inside a WHILE that reads each record and writes on the PAGE the results
echo "<a href='#' id='$intIdType'>";//Starts creating the link
echo "$intIdType -";
echo $arrBusinessTypes["business_Description"];
echo "(";
echo " $count1 )"."</a>";
Now, after the results are on the page it will look like this:
$intIdType $arrBusinessTypes $count
--------------------------------------------
1 -Auto Sales ( 1 )
2 -Auto Repair ( 1 )
5 -Web Desig & I.T. Services( 2 )
6 -Computer Shop ( 1 )
The above result displays each rown as a link where I can click on it, but nothing happens. Even just a simple Alert in javascript does not show up. It seems that it never reaches even the Javascript at all.
What I need now is to retrieve that PHP generated code on the page by a Javascript file, that will allow me to use the hiperlink generated by PHP into the .HTML page
It works if I write directly into the page what PHP is suppose to write. I wonder if this happens because Javascript can not read posted data from PHP into the page.
The Javascript File looks like this:
window.onload=post_result
function post_result() {
$("#1").click(function() { //This is the HREF ID that is written by PHP into the page
$('#list_results').load("results.php");//This seeks to run a PHP file in a DIV
$('.title').text('Listing Categories');//This just replaces the Title in the page
})
I'm just a beginner trying. Thanks for any help.
echo "<a id='$intIdType'>";//Starts creating the link echo "$intIdType -";
echo "$intIdType -";
echo $arrBusinessTypes["business_Description"];
echo "("; echo " $count1 )"."</a>";
just remove href attribute and try
Remark #1: quote custom data when outputs it to HTML:
echo $arrBusinessTypes["business_Description"]; must be
echo htmlspecialchars($arrBusinessTypes["business_Description"]);
Remark #2: you don't need window.onload handler here. In this piece of code you select complex way to do simple thing. Why do not write direct onclick handler? Write function loading some data depending of parameter and do something like:
$htmlspecialchars = function($s){return htmlspecialchars($s);};
echo <<<HTML
<a href='#' id='$intIdType' onclick='loadInfo($intIdType)'>
$intIdType -{$htmlspecialchars($arrBusinessTypes["business_Description"])} ( $count1 )
</a>
HTML;
(converted to heredoc to make HTML more clean)

Categories

Resources