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
During a while loop in PHP I want to create following link:
echo '<a onclick="getSolution('.ResultArray['qid'].')" style="color: red;">Lösung anzeigen</a>';
But there it is a mistake. It will not take the $ResultArray['qid'] as a parameter for the javascript function. I need this parameter for define which div it has to take when clicking on the link.
Here you get the complete while loop in php:
while($ResultArray = mysqli_fetch_array($getQuestions)) {
echo '<p>';
echo $ResultArray['question'];
echo '<br />';
echo '<input type="text" style="width: 500px;"/>';
echo '</p>';
echo '<a onclick="getSolution('.ResultArray['qid'].')" style="color: red;">Lösung anzeigen</a>';
echo '<div id="'.$ResultArray['qid'].'" style="visibility: hidden">';
echo $ResultArray['answer'];
echo '</div>';
}
How I can fix this problem?
You're trying to reference your ResultArray variable without prefacing it with your $ symbol.
Corrected:
echo '<a onclick="getSolution('.$ResultArray['qid'].')" style="color: red;">Lösung anzeigen</a>';
echo '<a onclick="getSolution('.ResultArray['qid'].')"
^^^^^^^^^^^^---undefined constant, since it has no "$"
You must have $ResultArray in there. Without the $, it's a constant, and you cannot have constant arrays.
Related
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 2 years ago.
Improve this question
I am working on a PHP project and I need to echo the dynamic confirmation text. I am trying with following code:
<a href="#" onclick='return confirm(<?php echo $instance->translator->__("Are you sure you want to delete this video?"); ?>)'> Remove</a>
Error:
SyntaxError: missing ) after argument list
how can I solve this ?
You need quotes in the JS/HTML too
<a href="#"
onclick="return confirm('<?php echo $instance->translator->__("Are you sure you want to delete this video?"); ?>')"> Remove</a>
Alternative
<? $areyousure = $instance->translator->__("Are you sure you want to delete this video?"); ?>
<a href="#"
onclick="return confirm('<?= $areyousure ?>')"> Remove</a>
Even better:
<div id="linkContainer">
Remove
</div>
<script>
const areyousure = '<? $instance->translator->__("Are you sure you want to delete this video?"); ?>';
document.getElementById('linkContainer').addEventListener('click', function(e) {
const tgt = e.target;
if (tgt.classList.contains('remove')) {
if (confirm(areyousure)) removeSomething(tgt.dataset.id)
}
});
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 5 years ago.
Improve this question
How to echo in php?
<div class="city" onclick="openCity(event,'London')">
I am try write sintax :
echo ' < div class=" city " onclick=" openCity(event,'London') " > ';
But event onclick not working
You have an issue with your quotes. You must escape the ones that suround your "London" arguement. Try this instead:
echo ' < div class=" city " onclick=" openCity(event,\'London\') " > ';
You might getting javascript syntax error due to single quote. Please you started echo with single quote. So need to handle inner single quotes. You can handle it in two ways
echo '<div class=" city " onclick="openCity(event,\'London\') ">';
or
echo "< div class=\" city\" onclick=\" openCity(event,'London');\" >";
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 7 years ago.
Improve this question
I don't know much about jQuery. Here I am trying to implement a closure to attach a click event to each anchor tag so that each of them will alert a certain number once blicked. But I am getting the following error:
SyntaxError: missing ) after argument list
};})(i);
can anyone help me with this problem?thanks :)
Code:
<div id='pageBox'>
<ul id='pageContainer'>
<?php for($i=1;$i<=$pagenum;$i++){?>
<li><a href=''><?php echo $i;?></a></li>
<?php }?>
</ul>
</div>
<script>
for(i=1;i<=<?php echo $pagenum;?>;i++){
$('#pageContainer li a').click((function(i){return function(event){
event.preventDefault();
alert(i);
};})(i);
);
}
You don't need closure here. This can be achieved using simple approach. Persist php variable $i in data-* prefixed custom attribute, which can be fetch using .data()
Change your HTML as
<ul id='pageContainer'>
<?php for($i=1;$i<=$pagenum;$i++){?>
<li><a href='' data-id='<?php echo $i;?>'><?php echo $i;?></a></li>
<?php }?>
</ul>
Script
$('#pageContainer li a').click(function(){
alert($(this).data('id'));
});
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 7 years ago.
Improve this question
what is wrong in following code as when I remove the php variable $var every thing work but I need to insert the id value which equals 5000 in a PHP variable $var
echo '<div id="img1" style="position:absolute;left:81px;top:127px;width:12px;height:12px;z-index:65;"><img src="img/image.png"'.$var=.' id="5000" alt="" style="width:12px;height:12px;"></div>';
What's up with the "=" in .$var=.
Remove it.
$var = '5000'
echo '<div id="img1"style="position:absolute;left:81px;top:127px;width:12px;height:12px;z-index:65;"><img src="img/image.png"'. $var .' id="5000" alt="" style="width:12px;height:12px;"></div>';
Not sure the HTML is correct.
Remove the = its causing 1 of the errors
The variable is being inserted out of the id="x" part of the tag
Remember PHP is CASE SENSITIVE that means $var isn't the same as $Var or $VAR
Here is the correct code:
$var = 5000;
echo '<div id="img1" style="position:absolute;left:81px;top:127px;width:12px;height:12px;z-index:65;"><img src="img/image.png" id="'.$var.'" alt="" style="width:12px;height:12px;"></div>';
You can try:
$var = 5000;
echo '<div id="img1" style="position:absolute;left:81px;top:127px;width:12px;height:12px;z-index:65;"><img src="img/image.png" id="' . $var . '" alt="" style="width:12px;height:12px;"></div>';
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
<script type="text/javascript">
function Invest()
{
alert("Mechanical /n Electrical /n Computer /n Civil");
}
function create()
{
alert("Graphic /n Interior /n Architecture");
}
function motivate()
{
alert("Business Administration /n Accounting and Finance");
}
</script>
The above code is my javascript code
<form action="main.html" method="post">
<?php
$v2 = $_GET['dropdown'];
if ($v2=="investigative" )
{
echo "<h3>It's recommended that you follow</h3><h2>Engineering School</h2>";
}
else if ($v2=="creative" )
echo "<h3>It's recommended that you follow</h3><h2>Arts School</h2>";
else if ($v2=="motivated" )
echo "<h3>It's recommended that you follow</h3><h2>Business School</h2>";
?>
What i want to do is to change my echo to a div onclick so it will call my function from javascript and show the information i have inside it.
Something like this
echo ""<div onclick=Invest();"<h3>It's recommended that you follow</h3><h2>Engineering School</h2>";
When I do that thought i get an error
Parse error: syntax error, unexpected 'onclick' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\MyProject\eval.php on line 35
What am I doing wrong and how to make that work? I am new at php :/
Not something like this echo ""<div onclick=Invest();...
You need to do it like this put div tag inside double quotes for onclick attribute open single quotes because double quotes are already opened
echo "<div onclick='Invest()'><h3>It's recommended that you follow</h3><h2>Engineering School</h2></div>";