Fiqhi Posted February 27, 2014 Share Posted February 27, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/ Share on other sites More sharing options...
WebStyles Posted February 27, 2014 Share Posted February 27, 2014 You don't need to escape the single quotes if they're not inside other single quotes. <a href="javascript:checker('checker_r.php','a')"><img src="images/accept.png" alt="Accept" /></a> Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470959 Share on other sites More sharing options...
Fiqhi Posted February 27, 2014 Author Share Posted February 27, 2014 (edited) 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> '; Edited February 27, 2014 by Fiqhi Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470963 Share on other sites More sharing options...
WebStyles Posted February 27, 2014 Share Posted February 27, 2014 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470964 Share on other sites More sharing options...
Fiqhi Posted February 27, 2014 Author Share Posted February 27, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470966 Share on other sites More sharing options...
WebStyles Posted February 27, 2014 Share Posted February 27, 2014 (edited) 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. Edited February 27, 2014 by WebStyles Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470967 Share on other sites More sharing options...
Ch0cu3r Posted February 27, 2014 Share Posted February 27, 2014 When dealing with Javascript make sure you have your browsers console open (try pressing F12 and then clicking the console tab) and making sure no javascript errors are being reported when you click the link for calling the checker javascript function. Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470970 Share on other sites More sharing options...
Fiqhi Posted February 27, 2014 Author Share Posted February 27, 2014 (edited) i dnt get a popup if the function is in the different file from the button. if it's in same file, the popup show up and if im using my own function, both won't work. still not triggered. Maybe because my function call others function in different file too Edited February 27, 2014 by Fiqhi Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470972 Share on other sites More sharing options...
WebStyles Posted February 27, 2014 Share Posted February 27, 2014 check if you're by any chance including 2 functions with the same name. Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470975 Share on other sites More sharing options...
Fiqhi Posted February 27, 2014 Author Share Posted February 27, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1470976 Share on other sites More sharing options...
Ch0cu3r Posted February 28, 2014 Share Posted February 28, 2014 Try change @name= to name= Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1471027 Share on other sites More sharing options...
Zane Posted February 28, 2014 Share Posted February 28, 2014 Instead of concatenating several quoted and double quoted strings together, why not make things easier on yourself and use a HEREDOC? Quote Link to comment https://forums.phpfreaks.com/topic/286586-i-cant-call-this-function/#findComment-1471085 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.