I'm trying to create a keyboard with characters that will add the pressed character to the input box. I created a function which I call with the onClick event and pass the character to be added. The problem is, the browser is interpreting it wrong due to the quotes within quotes. How can I format it so there isn't an issue with opening the parameter with double and closing with single quotes?
Here's the function:
function showKeyboard(){
var keyboardHtml = "<div class='keyboard'>" +
"<a class='char-button' onClick='addChar('à'); return false'>à</a>" +
"<a class='char-button' onClick='addChar('â'); return false'>â</a>" +
"<a class='char-button' onClick='addChar('ç'); return false'>ç</a>" +
"<a class='char-button' onClick='addChar('è'); return false'>è</a>" +
"<a class='char-button' onClick='addChar('é'); return false'>é</a>" +
"<a class='char-button' onClick='addChar('ê'); return false'>ê</a>" +
"<a class='char-button' onClick='addChar('ë'); return false'>ë</a>" +
"</div>";
var element = document.getElementById("quiz");
element.innerHTML += keyboardHtml;
}
Here's how the browser (Chrome) sees it:
The error lies within the quotes in the onclick event. By the way, the reason I'm doing it like this is because I only want to show the keyboard in certain instances (textbox questions that require the characters, not multiple choice ones).
If anyone has a fix or a more efficient way, I'd love to hear it.