Jump to content

[SOLVED] Onclick


Daney11

Recommended Posts

<script language="JavaScript">
function surroundText(text1,text2) {
             if (document.comment_form.comment_body.createTextRange && document.comment_form.comment_body.caretPos) 
{  
		 var caretPos = document.comment_form.comment_body.caretPos;      
		 caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;}
		 else document.comment_form.comment_body.value += text1 + text2;document.comment_form.comment_body.focus(caretPos)}function storeCaret(text) 
{ if (text.createTextRange) {text.caretPos = document.selection.createRange().duplicate();

}

}

</script>

 

<td width="508" height="19" valign="middle">  <a href="#" onclick="surroundText(':angel:', ' ');"><img src="smileys/face-angel.gif" border="0"></a></td>

 

Hey guys, im using the above codes to create an onclick event where if u click an image it puts the text into the textarea. It works ok but one problem is that when it is clicked it refreshes the page and the link comes up link.php# and the text is there, which isnt a problem but the page gets put back to the top and the comment area is at the bottom. Anyone know how to fix it so it stays where i left the page?

 

Thanks

Link to comment
Share on other sites

at the end of your function, add: "return false;"

 

that will keep it from following the link (which you have set to # and therefore reloads the page).

 

<script language="JavaScript">
function surroundText(text1,text2) {

  .... all your stuff here ...

return false;
}

</script>

 

edit, you could also put it after you call the function in the link itself:

<a href="#" onclick="surroundText(':angel:', ' '); return false;"> </a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.