Having trouble obtaining the value of a textbox

I am trying to create an inout text box. The user will enter a code then press a button to move from scene to scene. I am having difficulty reading the text from the box.

I understand that I need to define the input box in the html markup widget. That I have done with no problem.

hypeDocument.getElementById(‘tb1.value’);
is what I am using to try to get the value of the box, but I know this syntax is wrong and I suspect I woiuld have to get through the ID of the formfield as well.

tb1 is the ID of the textbox. So I am looking for the correct syntax to get the value of the textbox.

I would appreciate even the code to get an alert to tell be the value of the textbox.

Any help is greatly appreciated.

Best
PF

alert(document.getElementById('tb1').value);

:wink:

To answer more throughly in case you didn’t know how to … put this inside the innerHTML of a rectangle

<input type="text" id="tb1">
<input type="submit" onclick="alert(document.getElementById('tb1').value)">

returns 'undefined', which is what I have been getting. Thanks for the reply

edited above for you :wink: :arrow_up:

Ahhhhh...YAY! Made my day. TYVM

Here’s another usage example. That shows a Hype approach using the API

textInputListener-v2.zip (22.0 KB)

You could adapt this to check for input and then show a specific scene.

For example:

text.addEventListener("keypress", function(event) {
    if (event.keyCode == 13) { // Enter key
        if (text.value == "12345") {
            hypeDocument.showSceneNamed('Page2', hypeDocument.kSceneTransitionCrossfade, 1.1)
	} else {
	    hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1);
	}
    }
});
3 Likes