WARNING: Please read the statement allow before preceding on to the hypothetical thought exercise following it.
Harlowe (1.x or 2.x) does not currently have in-built support for entering Reader supplied data via in-page input elements (like text field).
I strongly suggests visiting the Harlowe Issue page and either requesting that such macros be added to the story format or adding your support to any such existing request, and I strongly suggest doing that instead of considering the use of the following thought exercise within an actual story.
The following thought exercise uses internal knowledge about the implementation and undocumented features of the Harlowe v2.0.1 engine, because of this the following may stop working for any later version of Harlowe 2.x
The following thought exercise is not a recommendation and you use it at your own risk.
1. The following Javascript creates a method named CustomScripts.updateVariable which can be used to update a story variable based on the contents of a HTML input text field. The method takes a single parameter which is the name of the story variable without the leading dollar sign ($), it also expects the input text field to have the same name. The method uses an undocumented Harlowe feature to update the value of a story variable.
Place the following Javascript code within your story's Story Javascript area.
if (typeof window.CustomScripts == "undefined") {
window.CustomScripts = {
updateVariable(inputName) {
// Get the value from the input textbox at time of click.
var value = $("input[name='" + inputName + "']")[0].value;
// Update the variable.
State.variables[inputName] = value;
}
};
};
2. Place the following TwineScript within a Passage. it does three things:
a. It initialises a story variable named $fname which will be updated with the entered value.
b. It creates a HTML input text field named fname which will be used by the Reader to enter a value, this field has been assigned a default value of Johnson.
c. It creates a button which calls the CustomScripts.updateVariable when select, which in turn causes the current value of the fname input text field to be assigned to the $fname story variable.
(set: $fname to "")
<input type="text" name="fname" value="Johnson">
<button type="submit" onclick="CustomScripts.updateVariable('fname')">Save value to variable</button>
3. You can test the above TwineScript by adding a markup link to the end of code in point 2 and then using TwineScript like the following within the targeted passage.
fname: $fname
... if you visit the target passage before selecting the Save value to variable button you will see the initial value, and if you visit the target passage after selecting the button you will see the entered value.