How do I make this work?
<a href='javascript:func("Jack'S Birthday")'>Jack's Birthday</a>
            Asked
            
        
        
            Active
            
        
            Viewed 158 times
        
    -2
            
            
         
    
    
        jforex78
        
- 315
- 2
- 11
- 
                    Any reason you need to abuse `href` for JavaScript code? – Sebastian Simon Mar 17 '18 at 17:51
4 Answers
1
            Do as follows:
// How about using variables instead?
var emily = "Emily'S Birthday"
var birthdays = {
  john: "John'S Birthday"
}
function func(val) {
  console.log(val);
}<!DOCTYPE html>
<html>
<body>
  <a href='javascript:func("Jack'S Birthday")'>Jack's Birthday</a>
  <br>
  <a href="javascript:func('Norman\'S Birthday')">Norman's Birthday</a>
  <br>
  <a href="javascript:func(emily)">Emily's Birthday</a>
  <br>
  <a href="javascript:func(birthdays.john)">John's Birthday</a>
</body>
</html>Explanation:
- Keep single quotes within double quotes when you escape using backslash \
- Use double quotes within single quotes when you use $apos;
- Best of all, use variables, they ease a lot of pain - - a. You don't have to go into html to modify values, 
 b. these can be declared at one place, or a single file,
 c. They can be fetched from back-end
 d. Best yet, no need to deal with quotes!
 
    
    
        Abhijit Kar ツ
        
- 1,732
- 1
- 11
- 24
- 
                    Thanks. But none of the above actually shows Norman'S Birthday. It does say Norman\'S Birthday with a "\". – jforex78 Mar 17 '18 at 18:36
- 
                    
- 
                    
- 
                    Thanks - this works in JavaScript. I've edited my question to show the production problem we are having with FTL expansion. – jforex78 Mar 18 '18 at 22:54
1
            
            
        Apparently you can't escape characters within HTML attributes. The proper way to go would be to use HTML entities like ' :
<a href='javascript:console.log("'")'>click me</a>0
            
            
        If possible, do it this way
<html>
  <header>
    <script>
    function func(x) {
      alert(x);
    }</script>
  </header>
  <body>
    <a href="javascript:func('Norman\'S Birthday')">Birthday</a>
  </body>
</html>
 
    
    
        D. Seah
        
- 4,472
- 1
- 12
- 20
- 
                    If possible, an actual button should be used, and `addEventListener`. – Sebastian Simon Mar 17 '18 at 18:10
0
            
            
        Convert to NCR. This should work.
<html>
    <a href='javascript:func("Norman'S Birthday")'>Birthday</a>
</html>
Or.
<html>
    <a href='javascript:func("Norman'S Birthday")'>Birthday</a>
</html>
 
    
    
        Valerii Strilets
        
- 164
- 8