Daney11 Posted December 6, 2007 Share Posted December 6, 2007 <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 Quote Link to comment Share on other sites More sharing options...
micah1701 Posted December 6, 2007 Share Posted December 6, 2007 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> Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 6, 2007 Author Share Posted December 6, 2007 Thanks mate, where abouts in my function should i add that? Quote Link to comment Share on other sites More sharing options...
micah1701 Posted December 6, 2007 Share Posted December 6, 2007 Thanks mate, where abouts in my function should i add that? I edited my above post, hope that helps Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 6, 2007 Author Share Posted December 6, 2007 Awesome, thanks <3 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.