2

I'm using the onclick event to populate an input tag dynamically, the onclick is constructed server side with database values. It works great until the value I'm passing contains an apostrophe. The function never fires because the delimiters in the HTML conflict. Any help appreciated.

    <span  onclick='putHName("DANCER'S CALL");'>
       DANCER'S CALL
    </span>

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

1 Answers1

1

Change your quotations around and escape the single quote using \:

onclick="putHName('DANCER\'S CALL');"
BenM
  • 52,573
  • 26
  • 113
  • 168