what i need
- i need to call onclick function from php file.
php code
$content .= '
<div class="evt_date" >
<meta itemprop="startDate" content="'.$data[$k]['startDate'].'">
<meta itemprop="endDate" content="'.$data[$k]['endDate'].'">
<span><button type="button" class="btn btn-primary btn-listing" onClick="favaorite('.$data[$k]['id'].',"'.$data[$k]['city'].'","'.$data[$k]['country'].'","'.$data[$k]['event_url'].'")">Addtofavorite</button>
</span>
javascript code
function favaorite(sess_id,city,country,event_url)
{
console.log(sess_id);
console.log(city);
console.log(country);
console.log(event_url);
}
Mosè Raguzzini
15.9k1 gold badge34 silver badges46 bronze badges
asked Mar 18, 2015 at 10:55
afeef
5773 gold badges9 silver badges27 bronze badges
-
1Unrelated to the error, but "favaorite" is actually spelled "favorite"Cerbrus– Cerbrus2015年03月18日 10:59:44 +00:00Commented Mar 18, 2015 at 10:59
2 Answers 2
Check this:
$content .= '<div class="evt_date" >
<meta itemprop="startDate" content="'.$data[$k]['startDate'].'">
<meta itemprop="endDate" content="'.$data[$k]['endDate'].'">
<span><button type="button" class="btn btn-primary btn-listing" onClick="favaorite('.$data[$k]['id'].',\''.$data[$k]['city'].'\',\''.$data[$k]['country'].'\',\''.$data[$k]['event_url'].'\')">Addtofavorite</button>
</span>';
answered Mar 18, 2015 at 11:02
prava
3,9742 gold badges26 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
afeef
but id "t understand logic adding (\',\'') in php
prava
Because compiler is thinking it is end of the method, as you gave double quote. check for this piece of code you wrote -
onClick="favaorite('.$data[$k]['id'].',". Compiler is checking this is the whole method, and it is searching for the closing brace now.prava
Even you can use strip `` with double quote, but better would be with single quote. We are just stripping the single quote here.
Separate the multiple quotes, ie quotes within quotes.
$click_fnt = "favaorite($data[$k]['id'],$data[$k]['city'],$data[$k]['country'],$data[$k]['event_url'])";
and add it to your code
$content .= '<div class="evt_date" >
<meta itemprop="startDate" content="'.$data[$k]['startDate'].'">
<meta itemprop="endDate" content="'.$data[$k]['endDate'].'">
<span><button type="button" class="btn btn-primary btn-listing" onClick="'.$click_fnt.'">Addtofavorite</button>
</span>';
This way it wont confuse the compiler nor the programmer.
Comments
default