PDA

View Full Version : onClick and php



viktor
03-07-2010, 06:01 PM
Hey guys,

I need to insert php inside onClick. Could use some help here.

I got this: <?php echo $location; ?>
This needs to go inside onClick.

This is the onclick code:

onclick="javascript:PayScaleExtension.displaySalaryCalculator('Registered Nurse (RN)', 'Seattle', 'Washington', 'United States');return false;">

It needs to replace Seattle and Washington, just one variable.

Thanks.

Schmoopy
03-07-2010, 06:16 PM
Could do it like this:



$location = array("'Seattle'", "'Washington'");




onclick="javascript:PayScaleExtension.displaySalaryCalculator('Registered Nurse (RN)', <?php echo implode(', ', $location); ?>, 'United States');return false;">


Ouput:

onclick="javascript:PayScaleExtension.displaySalaryCalculator('Registered Nurse (RN)', 'Seattle', 'Washington', 'United States');return false;">

viktor
03-07-2010, 06:44 PM
Thanks, it does work but the script needs separate values for city and state, which I do have. Here's what I tried but it displays the values instead of being inside onClick event.



<?php
$info = array("'$title'",",","'$city'",",","'$state'");
?>

onclick="javascript:PayScaleExtension.displaySalaryCalculator(<?php echo implode(', ', $info); ?> , 'United States');return false;">


It pulls required values, but I guess I'm missing something.

Thanks.