FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

javascript - another way to do this

 


Jaspa
Hi everyone

I'm trying to add a click counter to a list of links that are displayed from a mysql Db.

I have something that works but when the a link is clicked a new window opens to the links destination(which is right Smile), but then focus is returned to the old window and an alert message displayed with an 'ok' button that needs to be clicked.

I would like to get rid of the alert msg.

Also the js library I'm using is - fleegix.js which I would like to change of mootools.js (since it's already being loaded for other purposes).

This is what I have so far...

Link displayed with link id passed to js via '$am_id' var
Code:
<div class="Tlink">Tx link: <a href="'.$amlink.'" onclick="Amhit('.$am_id.');" target="_blank">'.


js to call the counter.php file
Code:

function msg(resp) {
   alert(resp);
}

function Amhit(amid) {
   fleegix.xhr.doGet(msg, 'amcnt.html?amid='+amid, 'text');
}



And the counter.php to update the Db
Code:

$amid = $_GET['amid'];

if ($amid !=""){

$table = $modx->getFullTableName('am');
$rs = $modx->db->select('clicks', $table, 'id="'.$amid.'"');
      $row = $modx->db->getRow($rs);
      $hits = $row['clicks'];
      
      $hit = $hits+1;
      
      $modx->db->query("UPDATE $table SET clicks='$hit' WHERE id='$amid' ") or die(mysql_error());
      
 echo "update of record $amid successful!";
 } else {
echo "update failer!! What - no id!!";
}


So... does anyone know how to do this with mootools.js or if you have a sugestion for a better way of achiving this your help is much appreciated.
Stubru Freak
You could search through your library and just remove the line that makes the alert box.

That would be the easiest solution in my opinion.
Jaspa
Dhuu! I don't know why I didn't think of that. Rolling Eyes

Thanks Stubru Freak, that worked to stop the alert box.

But rather than search the library I did this:

Code:

function msg(resp) {
   //alert(resp); -- commented out to stop alert box showing
}


However I would still like to accomplish this using the Mootools.js, Just to save having to load two different js libraries.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.