Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Can a default value be set with customScripts.updateNamedHook user input method?

This routine works fine, but I would like to pre-set the values.
if (typeof window.customScripts == "undefined") {
	window.customScripts = {
		updateNamedHook: function(hookName) {
			var value = $("input[name='" + hookName + "'], textarea[name='" + hookName + "']")[0].value;
			// Find the named hook node and set the text inside.
			$("tw-hook[name*='" + hookName + "']").text(value);
		}
	}; 
};

and in the passage I use the standard code
[]<Answer1|. <input type="text" name="Answer1" value="">

My screen has a menu of input fields using the above Javascript, then I progress to the next passage, which prints a report based on the inputs.

I would like to back up to the input screen and change one or more fields and then reprint.
But of course all the fields are blank and have to be re-entered

I tried
<Answer1|. <input type="text" name="Answer1" value=$Value1>

But that just pre-sets the data field with the literal "$Value1" rather than its contents

Comments

  • You need to state which Story Format you are using when you ask a question, as answers can be different for each one. Based on your code examples I am going to assume you are using Harlowe.

    You can use a (print: ) macro to dynamically create your input element, note the usage of both single and double quotes to allow the element's attributes to be set correctly.
    (set: $Value1 to "No idea")
    
    []<Answer1|. (print: '<input type="text" name="Answer1" value="' + $Value1 + '">')
    
  • My apology, I forgot to say "Harlowe"
    It works of course
    I still don't know how any human being can know as much as you do about Twine!
Sign In or Register to comment.