Jump to content

I can't call this function


Fiqhi

Recommended Posts

im trying to call a function from a button like this

<a href="javascript:checker(\'checker_r.php\',\'a\')"><img src="images/accept.png" alt="Accept" /></a>

Calling This Function

function checker(file,type) {
	var mail_tot;
	$("input[@name='mchk[]']:checked").each(function() {
		var sel_mail=$(this).val();
		if((mail_tot=='')||(mail_tot=='undefined')){
			mail_tot = sel_mail;
		}else{
			mail_tot = sel_mail+','+mail_tot;
		}
	});
	var a=$.get("checker_stat.php", {
		mail_tot:mail_tot,type:type},
		function(data){
			ShowSearch('',file);
                       
		}
	);
}

If i clicked the button nothing happens. This function will do some task to selected checkbox

Link to comment
https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/
Share on other sites

After deleting "\" i got

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in

These buttons are inside single quote

if ($idgroups!='') echo '
<div class="btn_holder">
<a href="javascript:procfrom(\'checker_r.php\',\'a\')"><img src="images/accept.png" alt="Accept" /></a> 
<a href="javascript:procfrom(\'checker_r.php\',\'d\')"><img src="images/decline.png" alt="Decline" /></a>
</div>
<div class="next_prev"><span id="naav">'.$paging->print_link().'</span> <span>'.$data[start].' - '.$data[end].' of Total '.$data[total].' Message</span></div>
';

then you didn't post the original code properly. The way you posted it made it seem like is was html, when in fact you are echo(ing) it from php. Try escaping the outer quotes:

echo '<a href=\'javascript:checker("checker_r.php","a")\'><img src="images/accept.png" alt="Accept" /></a>';

i've tried to change it into this

if ($idgroups!='') echo '
<div class=\'btn_holder\'>
<a href=\'javascript:procfrom("checker_r.php","a")\'><img src=\'images/accept.png\' alt=\'Accept\' /></a> 
<a href=\'javascript:procfrom("checker_r.php","d")\'><img src=\'images/decline.png\' alt=\'Decline\' /></a>
</div>
<div class=\'next_prev\'><span id=\'naav\>'.$paging->print_link().'</span> <span>'.$data[start].' - '.$data[end].' of Total '.$data[total].' Message</span></div>
';

it compiles but still no response when clicking

here's proof that it does work:

 

 

<html>
<head><script>
function checker(file,type) {
alert(file+' '+type);
}</script>
</head>
<body>
<?php
echo '<a href=\'javascript:checker("checker_r.php","a")\'>test</a>';
?>
</body>
</html>

replace your javascript function with a single echo like I did. If you get a popup, then the error is somewhere in the javascript function and not the button call.

ahh.. i got the real problem...

 

Thanks to Ch0cu3r

it's in 

function checker(file,type) {
	var mail_tot;
	$("input[@name='mchk[]']:checked").each(function() {
		var sel_mail=$(this).val();
		if((mail_tot=='')||(mail_tot=='undefined')){
			mail_tot = sel_mail;
		}else{
			mail_tot = sel_mail+','+mail_tot;
		}
	});
	var a=$.get("checker_stat.php", {
		mail_tot:mail_tot,type:type},
		function(data){
			ShowSearch('',file);
                       
		}
	);
}

Uncaught Error: Syntax error, unrecognized expression: input[@name='mchk[]']:checked

 

are my syntax wrong? i need this function to get id of selected checkbox

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.