Retrieve contenteditable changes like an input field.

Why does "name" work, but "nombre" doesn't. Does anyone know to make "nombre" work?

My name is <span id="nombre" contenteditable="true"> __.</span><br>
My name is <input type="text" id="name">. [[Nice to meet you.]]

[[Nice to meet you.]]:
      squiffy.set("name", jQuery("#name").val());
      squiffy.set("nombre", jQuery("#nombre").val());
      squiffy.story.go("Hello")


[[Hello]]:
Howdy, {name}!<br><br>
¡Buenos días, {nombre}!

Thanks!


Hello!

Try it with this change (using text() rather than val() for the SPAN element):

    squiffy.set("nombre", jQuery("#nombre").text());

Yep, you should be using text() or .html() to get the value (depending what you want to do if the user pastes formatted text into the field - .text() will strip the formatting, .html() will give it to you as a string of HTML).


Thank you so much K.V. and mrangel! Works like a dream! Now I can make the input of my Chinese parser game look more attractive!


Log in to post a reply.

Support

Forums