davey10101 Posted March 10, 2010 Share Posted March 10, 2010 Hi, Does anyone know how to check if a mailto link has been pressed? In my code I have an email link for a user but want to record if the mailto link has been pressed and add a record to a <textarea> box <?php echo "<a href=mailto:$Email>$Email</a>";?> any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 10, 2010 Share Posted March 10, 2010 That sounds like a job for JavaScript. Quote Link to comment Share on other sites More sharing options...
davey10101 Posted March 10, 2010 Author Share Posted March 10, 2010 aahhh was hoping to avoid javascript got no experience with it at all... *begins google search* :'( Quote Link to comment Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 10, 2010 Share Posted March 10, 2010 It's not bad at all, especially if you get a JavaScript library like MooTools or similar. Why kind of record would be added to the textarea? Quote Link to comment Share on other sites More sharing options...
davey10101 Posted March 10, 2010 Author Share Posted March 10, 2010 Ahhh just realised my textarea is done in php.... Saving the text inside the textarea to my database is done using php... So I can't use javascript to add a message 'onClick' to the textarea All I want to do is just add a simple message to the textarea to say "Email Sent" when the user clicks on the mailto link.. There must be away to do this surely? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 10, 2010 Share Posted March 10, 2010 This still looks like job for JavaScript. Maybe even for AJAX. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 Ahhh just realised my textarea is done in php.... Saving the text inside the textarea to my database is done using php... So I can't use javascript to add a message 'onClick' to the textarea All I want to do is just add a simple message to the textarea to say "Email Sent" when the user clicks on the mailto link.. There must be away to do this surely? I think you have a disconnect between what PHP and JavaScript do. PHP is used to create the HTML output that is sent to the browser. The browser does not know or care "how" that HTML content is produced (flat file, PHP, ASP, etc.). JavaScript is included in the HTML code and allows functionality to occure within the browser. The fact that you create the text area in PHP has no relevance on whether you can implement JavaScript. You will just nclude the JavaScript code in the output created by the PHP code. I'll post an example in a sec. Quote Link to comment Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 10, 2010 Share Posted March 10, 2010 As mjdamato said, the difference between JavaScript and PHP is that PHP is server side while JS is client side. It's definitely do-able with JavaScript, but won't necessarily be reliable in the instance a user has disabled JavaScript on their browser. I'd say your best bet would be to use Ajax because it would be "behind the scenes". If you use MooTools like I mentioned earlier (or similar), it should be relatively easy. If you add some more details, I should be able to come up with something, such as what else would be passed along (session id, username, etc.) to the page being called via Ajax? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 Here is an example PHP script which dynamically creates the email links and includes JavaScript to populate a textarea based on which links are clicked. <?php $contacts = array ( 'Michael' => 'michael@domain.com', 'Jane' => 'jane@domain.com', 'Dave' => 'dave@domain.com', 'Linda' => 'linda@domain.com', 'Bob' => 'bob@domain.com' ); //Create email links $emailLinks = ''; foreach($contacts as $name => $email) { $emailLinks .= "<a href=\"mailto:{$email}\" onclick=\"addEmailToList('{$name}: {$email}');\">{$name}</a><br />\n"; } ?> <html> <head> <script type="text/javascript"> function addEmailToList($value) { var textareaObj = document.getElementById('emailList'); textareaObj.value += ((textareaObj.value)?'\n':'') + $value; return true; } </script> </head> <body> Send an email to the following people:<br /> <?php echo $emailLinks; ?> <br /><br /><br /> Email links clickd:<br /> <textarea id="emailList" style="width:300px;height:150px;"></textarea> </body> </html> Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 ...won't necessarily be reliable in the instance a user has disabled JavaScript on their browser. I'd say your best bet would be to use Ajax because it would be "behind the scenes". What?! JavaScript is needed to run AJAX. When the user clicks the link you already have all the information you need in the browser (i.e. JavaScript can access it). So, what benefit would there be in using AJAX to do a server-side call? You would only be having the client-side JavaScript sending information based on what the user clicked to a server page so that page can return back what? The same information it just sent? Quote Link to comment Share on other sites More sharing options...
davey10101 Posted March 10, 2010 Author Share Posted March 10, 2010 OMG AMAZING! This is exactly what I'm looking for... I'll give it a try! Ill come crying back if it don't work for me lol. Thank you soo much guys much appreciated 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.