Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I get the following error and don't know where my mistake is:
Unexpected token <
Code (echo because of PHP used):
echo '<script type="text/javascript">
$(document).ready(function(){$("#sellerDrafts > tbody:last").append(';
foreach($this->view->sellercentral as $key2 => $value2)
{
echo '<tr><td><a href='. $value2->itemToken .'>Edit</a></td></tr>';}
echo '});</script>';
The problem is that you do not have quotes "" surrounding your append (and href), and it is not being closed with );.
echo '<script type="text/javascript">
$(document).ready(function(){$("#sellerDrafts > tbody:last").append("';
foreach($this->view->sellercentral as $key2 => $value2)
{
echo '<tr><td>Edit</td></tr>';
}
echo '");});</script>';
On a side note, this is really not the best way to do this. A better way to do this would be to build it in PHP first then hand it off to your javascript. Like so:
<?php
$table = "";
foreach($this->view->sellercentral as $key2 => $value2)
{
$table = '<tr><td>Edit</td></tr>';
}
?>
<script type="text/javascript">
$(document).ready(function(){
$("#sellerDrafts > tbody:last").append("<?php echo $table; ?>");
});
</script>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am confused as to why this piece of simple code is not displaying any data in either console.log or .actions class. There are no errors in console and I can see the correct value being returned in the payload window in inspector.
I would be grateful if someone could point out my error. Many thanks
<?php
$value = '10';
echo '<script>';
echo 'var value = ' . json_encode($value) . ';';
echo '$(".actions").text(value);';
echo 'console.log(value);';
echo '</script>';
?>
Make sure that jQuery is imported before your script, try this example.
<?php $value = '10';?>
<p class='actions'>Loading...</p>
<script src="jquery.min.js"></script>
<noscript>Javascript is disabled!</noscript>
<script>
$(function(){
var str = 'value = <?=$value?>';
$('.actions').text(str);
console.log(str);
});
</script>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have my code like this but the jquery is not giving response which writen in the bottom of the page in
<tr><th>Hindu</th>
<td><a href="javascript:void(0)" onclick="getIdies('<?php echo json_encode(explode(",",
$count[1 ]->OBCHinduOBC)); ?>')"><?php echo $count[1 ]->HinduOBC;?>
</a></td>
</tr>
This is my jquery
<sript>
function getIdies(values){
$.each(values,function(key,value){
alert(value);
});
}
</script>
The below line gives output like
<?php echo json_encode(explode(",", $count[1 ]->OBCHinduOBC)); ?>
output: ["200","500","700","675","54","567","678","867"]
You are not json decoding before use in our script,to decode the json you can use $.parseJSON
Just like this
<script>
function getIdies(values) {
$.each(values, function (key, val) {
alert(val);
});
}
Modification:-
Just change your html to
<tr><th>Hindu</th>
<?php $ids= json_encode(explode(",",$count[1]->OBCHinduOBC));?>
<td><a href="javascript:void(0)" onclick="getIdies({{$ids}})"><?php echo $count[1 ]->HinduOBC;?>
</a></td>
</tr>
Try this it will work fine.
Try putting explode(",", $count[1 ]->OBCHinduOBC) as a new variable before encoding it with json.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have this code:
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo "$item2[description]<br/>".PHP_EOL;
}
}
}
Now i need to modify this code to swing open the $item2[description]. I tried it like that:
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo ''Click
<div id="', $item2['id'], '" style="display: none">', $item2['description'], '</div>';
}
}
}
I think there is a mistake in some signs.
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo 'Click';
echo '<div id="'. $item2['id'].'" style="display: none">'. $item2['description'].'</div>';
}
}
}
you have some syntactical mistakes check this once
Use the . to concat strings
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo 'Click'.
'<div id="'.$item2['id'].'" style="display: none">'.$item2['description'].'</div>';
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So this is the part of my code that I'm trying to make it work :
while ($row = mysql_fetch_array($satt)){
echo "<li";
if($row["satake"] == $fns ) {
echo "class=\"selected\"";
}
echo "><a href=\"home.php?fn=".urlencode($row["satake"]).
"\">{$row["satake"]}</a></li>";
}
And upper in page I have defined these:
<?php
if (isset($_GET['fn'])){
$fns = $_GET['fn'];
$ys = "";
} elseif (isset($_GET['yosef'])){
$ys = $_GET['yosef'];
$fns = "";
} else
{
$ys = "";
$fns = "";
}
?>
And this is the css :
.selected { font-weight: bold; }
It doesn't give me any error and it runs smoothly but doesn't work.
While it is true that you were missing an space, you might want to take these steps in the future to avoid this confussion:
PHP is a template engine. Use it as such (put PHP presentation INSIDE html, and not the other way around).
Check out the dynamic generated solution with the browser inspector (Chrome or Firefox).
So, your code becomes much more readable and easier to spot errors when you do:
while ($row = mysql_fetch_array($satt)){
// Some light logic
$satake = $row["satake"];
$liclass = $satake == $fns ? "selected" : "";
$cleansatake = urlencode($satake);
// The presentation
?>
<li class="<?= $liclass; ?>" >
<a href="home.php?fn=<?= $cleansatake; ?>" >
<?= $satake; ?>
</a>
</li>
<?php
} ?>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am trying to echo a div class <div class="Box"> but not working. Can anyone help? Thanks.
echo '<div class="Box">
echo Anchor(T('Edit My Account'), '/profile/edit', FALSE, array('class' => 'Popup EditAccountLink'));
echo "<br />";
echo Anchor(T('Change My Password'), '/profile/password', FALSE, array('class' => 'Popup PasswordLink'));
echo "<br />";
$Inbox = 'Inbox';
$CountUnreadConversations = $Session->User->CountUnreadConversations;
if (is_numeric($CountUnreadConversations) && $CountUnreadConversations > 0)
$Inbox .= ''.$CountUnreadConversations.'';
echo Anchor(T('Inbox'), '/messages/all', 'Inbox');
</div>'
Your first and last lines are wrong, missing proper quotation marks and also an echo on the last line. It should be:
echo '<div class="Box">';
.... rest of code here...
echo '</div>';
You haven't terminated the string with ';.
echo '<div class="Box">';
Enable the error_reporting to E_ALL. Read on documentation. After this, you know what is happen.
This is a parse error. Enable error_reporting to E_ALL.