News:

Join the Facebook Fan Page.

Main Menu

Link Onclick

Started by mickjav, August 03, 2022, 09:58:42 AM

Previous topic - Next topic

mickjav

I have the following link

$my = '<a title="' . $mytitle . '" href="' . $flink . '?action=music;area=artists;sa=home;art=' . $art . ';fmt=' . $f .'#recs" onclick="myalbums($rec);"><img src="'. $img . 'add_my_music-20.png" alt="" align="absMiddle" /></a>';
This is used here
https://www.databasedreams.co.uk/testing/index.php?action=music;area=artists;sa=home;art=-2089005463

I have a require once if the template to the file that holds the Function being used.

I don't get any errors, but it just wont add anything to the table which is a simple table holding the rec_id, mem_id plus a primary key autonumber the link action work returning me to the page.

any help would be much appreciated

All the best mick

Diego Andrés

And what is the JavaScript function?
What is myalbums() doing with this info and what php function is receiving it?

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

Quote from: Diego Andrés on August 03, 2022, 10:15:39 AMAnd what is the JavaScript function?
What is myalbums() doing with this info and what php function is receiving it?

The function is in /Sources/Music/artist_module.php

myalbums() is the function that added the entry to the db

mick

Diego Andrés

But that's not how onclick works, it's an event listener and will attempt to find a javascript function called myalbums().
If you open your console after clicking on it, you'll probably see an error.

To accomplish what you are trying you need to use some ajax in this JavaScript function and send the info to the action that triggers myalbums() in the php side.

Hope this makes sense, someone else might be able to explain this better.
But in short, onclick will trigger a JavaScript function, not php.

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

Quote from: Diego Andrés on August 03, 2022, 10:25:34 AMBut that's not how onclick works, it's an event listener and will attempt to find a javascript function called myalbums().
If you open your console after clicking on it, you'll probably see an error.

To accomplish what you are trying you need to use some ajax in this JavaScript function and send the info to the action that triggers myalbums() in the php side.

Hope this makes sense, someone else might be able to explain this better.
But in short, onclick will trigger a JavaScript function, not php.


Thanks It does I think lol, I know JavaScript less than I know PHP
Hopefully somebody will be able to help.

All the best mick

Advertisement: