• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

embedding javascript function in href

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , I am trying to embed a javascript function in href like follows-

builder.append("<a href='");
builder.append("javascript:sendMail('servicedesk@bogota.oilfield.slb.com', mailSubject, mailBody)'>");
builder.append("HubAdmin</a>");

but while displaying it is not showing the link HubAdmin . what is the problem??
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

There are nested single quotes, which doesn't work. You need to replace either the inner or the outer set of single quotes by double quotes, which -since this is a Java string- you can do by putting a backslash in front of them.
 
shashikant shinde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now when i am trying with this combination
<a href=\"javascript:sendMail('servicedesk\@bogota.oilfield.slb.com', mailSubject, mailBody)\">Hub Admin</a>

it is also giving error in eclipse saying Invalid escape sequence.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is also giving error in eclipse saying Invalid escape sequence.



For some other reason, you decided to also escape the "@" sign.

Henry
 
shashikant shinde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Thanks for the response. Let me explain my requirement clearly.

I have a java-script method "sendMail('<email-id>', <mailSubject>, <mailBody>)" , inside my jsp file.

I want to display a message, (already using struts), that will contain a "a href" tag, and inside href , this javascript method needs to be referred.

My string message looks like follows:

You don't have administrator rights on 3 out of 84objects concerned,therefore this operation can not be allowed.Please send a mail (<mail referred to javascript:sendMail() using a href >) Hub Admin Support team to carry out this activity for you.

During run-time, this message gets printed in the jsp page, and if the user clicks on "mail" link, one new send mail outlook window needs to be opened, using sendmail() javascript method.

I am trying in the way i posted in the current thread. But, it is not helping me. Please suggest.

Thanks and Regards,

Shashikant Shinde.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we understand exactly what you're trying to do. I'm not sure what the "it" is in "it is not helping me", but did you fix the problem Henry mentioned?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We discuss JavaScript on a different forum. Moving.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic