Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't get function to work when fired by clicking on an image

Status
Not open for further replies.

ericw

Technical User
Apr 20, 2001
2
0
0
US
What I want to do is all too unbelievably simple. I have a function that inserts <B> and </B> tags around whatever is highlighted in a text area. When called with an <INPUT> button, it works fine, as in:

<INPUT TYPE=&quot;button&quot; VALUE=&quot;Bold&quot; ONCLICK=&quot;insertAtCaret(this.form.txtOther, document.selection.createRange().text.bold());&quot;>

All I want to do is use an *image* instead of a clunky <INPUT> button to fire the 'insertAtCaret' function. I have tried everything I can think of:

* putting the ONCLICK statement within the <IMG> tag
* putting the ONCLICK statement within an <A HREF=&quot;#&quot; ...> tag around the image
* calling the function from the <A HREF> attribute itself, as in HREF=&quot;javascript:insertAtCaret [etc...]&quot;

Nothing works that I can think of. Does anybody have any advice? Thanks in advance.
 
Try changing this.form.txtOther to document.form.txtOther?

Tim --
Tim <tim@planetedge.co.uk>
 
<SCRIPT LANGUAGE=&quot;Javascript&quot;>
function myfunction()
{...}
</SCRIPT>
...
<A HREF=&quot;javascript:void(null);&quot; onclick=&quot;myfunction();&quot;><IMG SRC=&quot;file.png&quot; BORDER=&quot;0&quot;></A>

That's worked for me in the past. Have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top