This should be easy but I’m just not getting it. I want to create a in a Hype scene where the user can type in a block of text (maybe 200 words) and then the Hype code makes that text available to a variable in a JS function that I can manipulate it under program control.
I can create a rectangle object (which becomes a div with a specific id (say ‘textIn’)) and assign its innerHTML to set it up as a textarea with specified width and height and other styles etc.
That looks good when I run the Hype, and I can type into that fine. But I cannot work out how to get that typed-in text into a JS variable inside a Hype function so I can work on it in the program. I thought I could just use
hypeDocument.getElementById(‘textIn’).value
but that returns undefined. Is it because I’ve already filled up its innerHTML to set up the properties? Or is it that somehow I need to properly terminate the text input. How? All I did was create a button that called a function to look at the div value (and that produced undefined).
Surely I don’t have to encapsulate it into a form and post it off to a URL?
It might be useful to post a zip of your .hype document that shows what you're doing. There could be several things that are wrong, though I think it is most likely what you describe here:
It sounds like you are setting up the Unique Element ID on the div. Then you have a textarea which is an element inside of that which does not have an ID.
Therefore when you call hypeDocument.getElementById('textIn').value you are calling .value on the wrong element since you are calling it on the div and not the textarea.
I'll also point out the code you posted is:
hypeDocument.getElementById(‘textIn’).value
but the tick marks are smart single quotes which would be a syntax error. You need to use ' or ". I'm guessing this was just a typing issue in the forum post though.
Anyways, if you want to access via the ID of the hype element to drill into the inner text area you'd use code like:
var textValue = hypeDocument.getElementById("textIn").querySelector("textarea").value;
Or it may be easier just to put an id on the text area itself, like <textarea id="textIn"></textarea> and then you can just do your code:
var textValue = document.getElementById("textIn").value;
This forum is great, especially if you live in the UK, when you can post a query at the end of the day, and there’s a good chance that someone in the USA (I’m guessing you are there) will reply coz it’s still early afternoon for them.