SyntaxError: missing ) after argument list php javascript [closed] - javascript

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)
}
});

Related

event on click not working in echo php [closed]

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');\" >";

How to implement a closure in jQuery [closed]

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'));
});

PHP Code inside HTML? [closed]

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>';

insert text into span class using jquery [closed]

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 have following html structure
<a id="myBtn" class="ui-link">
<span class="number"> </span>
<span class="button "> </span>
</a>
I want dynamically to insert some content into <span class="number">
var content = 99;
$('number').html(content);
but nothing change.
So what I need to do insert value into span that resulted node looks like this
<span class="number">99</span>
You are not using . to get class selector. Use $('.number') instead of $('number')
$('.number').html(content);
OR
$('.number').text(content);
insert text using class
var content = 99;
$('.number').html(content);
Try this:
$('.number').html(content);
You are referring to a wrong element. You can also do this:
$('.number').text(content);

Define javascript parameter in PHP [closed]

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.

Categories