(Harlowe) How do I save a text input field as a variable?

+1 vote
asked Mar 5 by Elliotpage (140 points)

Hello!

I am using Twine 2.2.1 with Harlowe 2.1.0 on Mac. 

I would like to have a text field that asks a user to enter a name, and then once they click "submit" it gets saved as a variable. (I do not want to use the "prompt" option as I dislike the popup from a user experience point of view).

I have read a number of very helpful posts which outline a way to do this via a hook using a little Javascript, but I have been unable to get these to work, as every time I try and get the page to save the name to a variable it gives me the error "A hook name cannot be stored"

From the Story Javascript:

if (typeof window.customScripts == "undefined") {
	window.customScripts = {
		submitName: function(inputName) {
			//Get the value of the textbox at time of click
			var newName = $("input[name='" + inputName + "']")[0].value;
			//Find the hook node based on name and set the text inside
			$("tw-hook[name*='" + inputName + "']").text(newName);
			//Log the Change
			console.log(inputName + " changed.")
		}
	}; 
};

And from the Passage:

(set: $UNAME = "Lancer")
Your Name: [Lancer]<fname|
<input type="text" name="fname" value="Lancer"><button type="submit" onclick="customScripts.submitName('fname')">[Update Name]<submitname|</button>

(click:?submitname)[(set: $UNAME = ?fname) [[Hillside]] ]

Any advice would be gratefully received - I have been dissecting this for a while and all the sources I have read say this should work but I cannot get it to!

Sources:
https://twinery.org/forum/discussion/4895/user-input-in-harlowe
https://twinery.org/forum/discussion/5634/user-input-in-harlowe-defining-variable-content-using-html-tags
http://twinery.org/forum/discussion/comment/6468/#Comment_6468

Please log in or register to answer this question.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...