I would like to have a
<input type="text" value=VARIABLENAME />.
Is there anyway I can do this? Putting value = “VARIABLENAME” interprets it as the name of the variable. But I would like to assign the content of the variable to the value property.
EDIT: The variable is from the text content of one of my tables. I got the variable by using doing something like this in my script tag.
selectedScheduleName = e.target.childNodes[0].wholeText;
Thank you.
Yes, you can assign a value to the input’s
valueproperty from a variable, e.g.:You do this in the JavaScript, after getting a reference to the
inputelement.So for instance, if you give the
inputanidvalue of “foo”, you can do this:…within a
scripttag. (Be sure that theinputhas already been added to the DOM first, either by putting the script after it — the bottom of thebodytag is good — or by usingwindow‘sloadevent or, if you use a library that supports one, some kind of “dom ready” event.)The element doesn’t have to have an
id, if you can get at it viagetElementsByTagNameor by theformelement’selementsarray, etc., etc.Handy references:
HTMLElement,HTMLFormElement, andHTMLInputElement