4 Replies - 30198 Views - Last Post: 07 January 2011 - 01:12 AM

#1 nitzgamz1988  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-January 11

How to get the value of <a href="#"> when click

Posted 06 January 2011 - 08:45 PM

Hi! good day!

I am currently creating a simple chatbox. I am having a problem how to have a smileys features in the chatbox. I've tried using an <href> for the images of the smileys. And when the user click a certain smiley image, I will just going to call the value for the image he/she clicked a while ago and then pass that value into the textbox. My question is How can i pass the value of < a href ="#" > when click. Thnx in advance.



Best regards "nitz"

Is This A Good Question/Topic? 0
  • +

Replies To: How to get the value of <a href="#"> when click

#2 fromTheSprawl  Icon User is offline

  • Bloodborne
  • member icon

Reputation: 522
  • View blog
  • Posts: 2,102
  • Joined: 28-December 10

Re: How to get the value of <a href="#"> when click

Posted 07 January 2011 - 12:13 AM

That could be done by using the getAttribute method.

linkHolder = document.getElementById("IDofyourhref");
theLink = linkHolder.getAttribute("href");



variable theLink will now hold the href value. Hope that helps. :sweatdrop:
Was This Post Helpful? 0
  • +
  • -

#3 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: How to get the value of <a href="#"> when click

Posted 07 January 2011 - 12:20 AM

Why don't you use the onclick event of the image itself, rather than using <a> tag?
Here's a snippet (untested):
<script type="text/javascript">
   function callFunc(imageElement) {
      alert(imageElement.src);
   }
</script>
<img src="happy.png" onclick="callFunc(this);" />


Was This Post Helpful? 1
  • +
  • -

#4 nitzgamz1988  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-January 11

Re: How to get the value of <a href="#"> when click

Posted 07 January 2011 - 12:43 AM

View PostMunawwar, on 06 January 2011 - 11:20 PM, said:

Why don't you use the onclick event of the image itself, rather than using <a> tag?
Here's a snippet (untested):
<script type="text/javascript">
   function callFunc(imageElement) {
      alert(imageElement.src);
   }
</script>
<img src="happy.png" onclick="callFunc(this);" />




Thank you. This help me a lot.

I have a follow up question. Instead of displaying it in alert form can i have it display in a input box. I have already a $ereg_replace for the images. Thnx in advance.

This post has been edited by nitzgamz1988: 07 January 2011 - 12:49 AM

Was This Post Helpful? 0
  • +
  • -

#5 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: How to get the value of <a href="#"> when click

Posted 07 January 2011 - 01:12 AM

That is quite easy. I would like you to try it.
First get the input box element using document.getElementById (look at the example fromTheSprawl showed). And then do some magic - Hint.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1