ColdFusion makes it simple to populate a form fiel...
# javascript
p
ColdFusion makes it simple to populate a form field with a previously submitted value: <input name="myVar" value="#form.myVar#"> Q: How do I do the same using JavaScript? If the values were in the url scope, I could use window.location.href, but they're in the form scope instead.
m
I don't believe JS knows about the form scope; you'd have to load them into a JS variable ahead of time.
p
I have to believe it has something to do with the FormData object, but I haven't figured it out yet. https://developer.mozilla.org/en-US/docs/Web/API/FormData
Yeah, I got into express body-parser and tapped out.
m
Items sent with FormData() can be found in the form scope, but JS can't directly access the CF form scope. You could probably use the FormData() object to set input values. But it's hard to tell without seeing how you are attempting to do this.
p
If we were running node.js:
Copy code
server = http.createServer(function(request, response) {
var data = '' request.on('data',function(chunk) { data += chunk; }) request.on('end', function() { console.log(JSON.parse(data).todo); // 'Buy the milk' response.end(); }) }) `````` But I'm not.
m
Are you sending your form with
FormData()
or just a regular form submit?
m
ezpz
<input id="anId" ...>
document.getElementById('anId').value = "#form.myVar#"