Author Topic: php inside onclick  (Read 1172 times)

0 Members and 1 Guest are viewing this topic.

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php inside onclick
« Reply #15 on: March 12, 2010, 01:06:54 PM »
It doesn't work because the variables $job and $country do not exist within your code. khr2003 was only posting a code suggestion, obviously they wont be able to know your exact variable names. You'll need to find out what variables hold the job and country.

My guess is $job should be $title and $contry should be $job_location

Offline V1ktorTopic starter

  • Irregular
  • Posts: 17
    • View Profile
Re: php inside onclick
« Reply #16 on: March 12, 2010, 02:30:51 PM »
Ahh wasn't paying attention. $job is $title.
$state and $country are static, I can set them to what I need. $city and $title are pulled from database.

When I changed $job to $title, it began doing what it did in the beginning... breaking onClick and just displaying those values... just like in that screenshot I showed earlier. I'm not sure its causing that.

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php inside onclick
« Reply #17 on: March 12, 2010, 05:25:27 PM »
echo out $title what does it contain? Something in that variable is breaking your HTML/Javascript.

Offline V1ktorTopic starter

  • Irregular
  • Posts: 17
    • View Profile
Re: php inside onclick
« Reply #18 on: March 12, 2010, 05:33:20 PM »
echo out $title what does it contain? Something in that variable is breaking your HTML/Javascript.

Hmmm didn't think about that. It seems like the $title is a link... so if it pulls Accountant, it's a link to that job and not just a word.

I will find out if there's another value I can pull.

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php inside onclick
« Reply #19 on: March 12, 2010, 05:50:15 PM »
In that case you can use strip_tags().

echo "<a href=\"http://www.payscale.com\" 
   title=\"Research Salary at PayScale\"
   onclick=\"javascript:PayScaleExtension.displaySalaryCalculator('"
.trim(strip_tags($title))."', '$state', '$city', '$city');return false;\">
   <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>"
;
« Last Edit: March 12, 2010, 05:51:47 PM by wildteen88 »

Offline V1ktorTopic starter

  • Irregular
  • Posts: 17
    • View Profile
Re: php inside onclick
« Reply #20 on: March 13, 2010, 11:56:29 PM »
In that case you can use strip_tags().

echo "<a href=\"http://www.payscale.com\" 
   title=\"Research Salary at PayScale\"
   onclick=\"javascript:PayScaleExtension.displaySalaryCalculator('"
.trim(strip_tags($title))."', '$state', '$city', '$city');return false;\">
   <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>"
;


Ahh FINALLY! We got to the bottom of this. I had to move vars around into their order for PayScale to read them properly (job, city, state, country), but it works!

Thanks for sticking around and helping me solve this puzzle.