V1ktor Posted March 9, 2010 Share Posted March 9, 2010 I need to display 3 php values inside onClick event. I tried code below, but clearly I'm missing something. It pulls values from db and displays them instead of staying within onClick. <?php $info = array("'$title'",",","'$city'",",","'$state'"); ?> onclick="javascript:PayScaleExtension.displaySalaryCalculator(<?php echo implode(', ', $info); ?> , 'United States');return false;"> This is what I'm trying to accomplish once it pulls values from db: onclick="javascript:PayScaleExtension.displaySalaryCalculator('Registered Nurse (RN)', 'Seattle', 'Washington', 'United States');return false;"> Thanks. Quote Link to comment Share on other sites More sharing options...
khr2003 Posted March 9, 2010 Share Posted March 9, 2010 hi try this <?php $info = array("'$title'",",","'$city'",",","'$state'"); $info = implode(', ', $info); echo "<a href='#' onclick=\"javascript:PayScaleExtension.displaySalaryCalculator($info , 'United States'); return false;\">Click here</a> Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 9, 2010 Author Share Posted March 9, 2010 Hey, thanks for reply. But still nothing, it displays it right next to the image link. Here's full code that I'm using: <?php $info = array("'$title'",",","'$city'",",","'$state'"); $info = implode(', ', $info); echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator($info , 'United States');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>" ?> This is how it displays it: Sales Representative', ,, 'Greece', ,, 'New York' , 'United States');return false;"> Plus image link next to it. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
shane18 Posted March 9, 2010 Share Posted March 9, 2010 Try <?php $info = array("'$title'","'$city'","'$state'"); ?> onclick="javascript: PayScaleExtension.displaySalaryCalculator(<?php echo implode(', ', $info); ?>, 'United States');"> That should display it like TITLE, CITY, STATE Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 9, 2010 Author Share Posted March 9, 2010 Still nothing. I realized I just need title and city variables passed, state is the same. Can I use js variables instead? I'm not sure how to insert them inside onClick though. <script type="text/javascript"> // <![CDATA[ var city = "' . $city . '"; var title = "' . $title . '"; // ]]> </script> <a href="http://www.payscale.com" title="Research Salary at PayScale" onclick="javascript:PayScaleExtension.displaySalaryCalculator(title,city,'New York','United States');return false;"> <img src="http://www.payscale.com/images/research_salary_bug.gif" alt="PayScale" width="109" height="23" border="0" /></a> Quote Link to comment Share on other sites More sharing options...
khr2003 Posted March 9, 2010 Share Posted March 9, 2010 Hey, thanks for reply. But still nothing, it displays it right next to the image link. Here's full code that I'm using: <?php $info = array("'$title'",",","'$city'",",","'$state'"); $info = implode(', ', $info); echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator($info , 'United States');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>" ?> This is how it displays it: Sales Representative', ,, 'Greece', ,, 'New York' , 'United States');return false;"> Plus image link next to it. Thanks for your help. isn't that what you wanted? displaying texts within the js? Do you mean that javascript is broken at some point? Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 9, 2010 Author Share Posted March 9, 2010 The variables inside onClick shouldn't display on the page next to the image button. This is the original code with static values: onclick="javascript:PayScaleExtension.displaySalaryCalculator('Registered Nurse (RN)', 'Seattle', 'Washington', 'United States');return false;"> I need to insert php variables inside onclick so they can be populated from database. The table I have setup already pulls $title and $city from database. All I need to figure out is how to insert them inside onClick without them breaking the code. See the image for what it looks like with: <?php $info = array("'$title'",",","'$city'",",","'$state'"); $info = implode(', ', $info); echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator($info , 'United States');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>" ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
khr2003 Posted March 10, 2010 Share Posted March 10, 2010 alright, here is another approach. first try to remove $info completely from js (just to know the js is working fine and the proble is with the php variables). if everything is ok then try to include the data of $info straight into the js without using implode: <?php echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator('$title','',",'$city',",",'$state' , 'United States');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>" ?> Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 10, 2010 Author Share Posted March 10, 2010 Ahh why it has to be pain in the butt. It still doesn't work. I tried removing php variables from onClick and run it like that... it works fine. Seems like having php variables inside onClick breaks it. Maybe convert php variable to js variable? That, technically, could work. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 10, 2010 Share Posted March 10, 2010 Why the array. Why complicate it to the point you become confused. You must already have the title,city and state var to put it into an array so why not just use them? echo "blah...blah onclick="javascript:PayScaleExtension.displaySalaryCalculator('$title', '$city', '$state', 'United States');return false;">";//escape quotes as needed HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 10, 2010 Author Share Posted March 10, 2010 Why the array. Why complicate it to the point you become confused. You must already have the title,city and state var to put it into an array so why not just use them? echo "blah...blah onclick="javascript:PayScaleExtension.displaySalaryCalculator('$title', '$city', '$state', 'United States');return false;">";//escape quotes as needed HTH Teamatomic Inserting php vars on their own with everything inside echo does the same thing, it breaks the code by displaying values next to the image button. Refer to image example to see what I mean. They need to stay inside onClick so when someone clicks on the image it opens window with information based on those values. Quote Link to comment Share on other sites More sharing options...
khr2003 Posted March 11, 2010 Share Posted March 11, 2010 ok. here is the code. I modified according to payscale website. You had many small mistakes in your script, but anyway it is working now on my computer. So if it does not work with you check the rest of your script. <?php $job = 'Registered Nurse (RN)'; $state = 'Seattle'; $city = 'Washington'; $contry = 'United States'; echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator('$job', '$state', '$city', '$contry');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>"; ?> Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 11, 2010 Author Share Posted March 11, 2010 ok. here is the code. I modified according to payscale website. You had many small mistakes in your script, but anyway it is working now on my computer. So if it does not work with you check the rest of your script. <?php $job = 'Registered Nurse (RN)'; $state = 'Seattle'; $city = 'Washington'; $contry = 'United States'; echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator('$job', '$state', '$city', '$contry');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>"; ?> Ok, I see. It works now. But, you redefined vars to the static options. In that file I already have php setup to call $title, $city, $state from a database. How can I connect that inside PayScale onClick event. Thanks for your help, really appreciate it. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 11, 2010 Share Posted March 11, 2010 if the variables, $job, $state, $city and $country are already defined in your script elsewhere then just delete these lines $job = 'Registered Nurse (RN)'; $state = 'Seattle'; $city = 'Washington'; $contry = 'United States'; If it still doesn't work you'll need to post more code, specifically where you're defining the above variables. Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 11, 2010 Author Share Posted March 11, 2010 Nope, for some reason it doesn't work when I comment out those vars. Here's the code in that file: <?php if ( ! ( defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); } global $_config; $make_national=$_config['make_jobs_national']; /* * 1:hepsini göster * 2:şirketin seçmesine izin ver; * 3:hepsini gizle * */ $hide=$_config['hide_company']; ?> <?php echo $simple_search_box_wide;?><br /> <?php echo $subcats;?> <?php if ($job_count==0) { echo _lkn_error_no_job; }else {?> <div style="padding-top: 20px;"> <div id="middleleftwidgetcontainer"> <div class="jobsfoundnosuggs" > <h1 style="margin: 15px 0px 8px;" class="searchInfo"><?php echo $job_count;?> - <?php echo temizleSlash($cat_name);?> <?php echo _lkn_jobs?></h1> </div> </div> <div style="clear: both;"></div> </div> <?php //kategoriye ait işlerin yazırılması başladı?> <div class="jl_wrap_div grad"> <table cellspacing="0" border="0" style="border-collapse: collapse;" class="jl_tbl"> <tbody> <tr id="gradtitle"> <th align="left" style="padding: 3px;padding-left: 15px;"><?php echo _lkn_job;?></th> <?php if ($hide!='3') {?> <th align="left" style="padding: 3px;"><?php echo _lkn_company;?></th> <?php }?> <?php if ($make_national=='0') {?> <th align="left" style="padding: 3px;"><?php echo _lkn_job_country;?></th> <?php }?> <th align="left" style="padding: 3px;"><?php echo _lkn_job_location;?></th> <th align="left" style="padding: 3px;"><?php echo _lkn_created;?></th> <th align="left" style="padding: 3px;">Salary</th> </tr> <?php $k=1; foreach ($rows as $row) { //print_r($row); $title=temizleSlash($row->title); $id=$row->id; $published=$row->published; $alias=$row->alias; $company_name=temizleSlash($row->company_name); $company_alias=$row->company_alias; $company_id=$row->company_id; $created=$row->created; $created=lknDate::formatDate($created); $job_location=$row->job_location; $city=$row->city; $state=$row->state; $location=array(); if ($city!='') { $location[]=$city; } if ($state!='') { $location[]=$state; } if (count( $location )>0) { $location= implode( ' , ', $location ); }else { $location= ' - '; } if ($hide=='2') { //şirketin seçmesine izin verilmiş $hide_company_name=$row->hide_company_name; }elseif ($hide=='1'){ $hide_company_name='0'; }elseif ($hide=='3'){ $hide_company_name='1'; } if ($hide_company_name=='1') { $company_name=_lkn_job_company_name_is_hidden; }else { $link_company="index.php?option=com_jobs&task=detail_company&id=$company_id:$company_alias" . $Itemid; $link_company=lknSef::url($link_company); $company_name="<a href=\"$link_company\">$company_name</a>"; } $link_job="index.php?option=com_jobs&task=detail_job&id=$id:$alias" . $Itemid; $link_job=lknSef::url($link_job); $title="<a href=\"$link_job\" class=\"jt\">$title</a>"; if ($k=='1') { $class='jl_odd_row'; }else { $class='jl_even_row'; } ?> <tr class="<?php echo $class;?>"> <td align="left"><?php echo $title;?></td> <?php if ($hide!='3') {?> <td align="left"><?php echo $company_name; ?></td> <?php }?> <?php if ($make_national=='0') {?> <td align="left"><?php echo $job_location;?></td> <?php }?> <td align="left"><?php echo $location;?></td> <td align="left"><?php echo $created; ?></td> <td align="left"> <script type="text/javascript" src="http://www.payscale.com/js/psextension.js"></script> <script type="text/javascript"> PayScaleExtension.affiliateId=''; PayScaleExtension.ServiceURL='http://www.payscale.com'; PayScaleExtension.jobListing = false; PayScaleExtension.backgroundColor = '#9a0000'; PayScaleExtension.textColor = '#ffffff'; PayScaleExtension.init(); </script> <?php //$job = 'Registered Nurse (RN)'; //$state = 'Seattle'; //$city = 'Washington'; //$contry = 'United States'; echo "<a href=\"http://www.payscale.com\" title=\"Research Salary at PayScale\" onclick=\"javascript:PayScaleExtension.displaySalaryCalculator('$job', '$state', '$city', '$contry');return false;\"> <img src=\"http://www.payscale.com/images/research_salary_bug.gif\" alt=\"PayScale\" width=\"109\" height=\"23\" border=\"0\" /></a>"; ?> </td> </tr> <?php $k=3-$k; } ?> </tbody> </table> </div> <?php //kategoriye ait işlerin yazırılması bitti?> <?php //sayfalama linkleri başladı?> <div style="margin: 5px; padding: 5px;"> <?php echo $paging_links;?> </div> <?php //sayfalama linkleri bitti?> <?php }?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 12, 2010 Share Posted March 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 12, 2010 Author Share Posted March 12, 2010 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 12, 2010 Share Posted March 12, 2010 echo out $title what does it contain? Something in that variable is breaking your HTML/Javascript. Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 12, 2010 Author Share Posted March 12, 2010 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 12, 2010 Share Posted March 12, 2010 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>"; Quote Link to comment Share on other sites More sharing options...
V1ktor Posted March 14, 2010 Author Share Posted March 14, 2010 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. Quote Link to comment 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.