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>';
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 needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to embedded the below jquery code in the following php variable $var
JQUERY Code:
<img src="images/image.png" id="Image1" alt="" style="width:30px;height:30px;">
PHP Code:
<?php $var = 'my_jquery_code'; return $var; ?>
You just need to escape the single quotes:
<?php
$var ='<img src="images/image.png" id="Image1" alt="" style="width:30px;height:30px;">';
return $var;
The only reasonable scenario I can think of where you would want to use onclick would be if you're dynamically loading the anchor element.
If so, this is probably better.
[script]
$(document).on('click', '.my_class_here', function() {
$('jQueryDialog1').dialog('open');
});
[/script]
[link_template]
...
[/link_template]
Then you would use AJAX or whatever voodoo you like to retrieve the link template (maybe while passing it some variables?) and add it to the page.
Alternatively, you can use $(document).find('.my_class_here').on('click', function... , but this is bad, performance wise.
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.