1

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);
}
1
  • 1
    Unrelated to the error, but "favaorite" is actually spelled "favorite" Commented Mar 18, 2015 at 10:59

2 Answers 2

1

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>';
Sign up to request clarification or add additional context in comments.

3 Comments

but id "t understand logic adding (\',\'') in php
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.
Even you can use strip `` with double quote, but better would be with single quote. We are just stripping the single quote here.
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.