Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mark VonGyer
21,239 PointsGet HTML form results for use in javascript function
Anyone know a solid way of getting radio HTML form question results processed into a javascript function?
Thanks!
Marcus Parsons
15,719 PointsIf you show us the code that you already have, we can further help you better!
Mark VonGyer
21,239 PointsI've changed the button to just a <p> that i will format to make it look like a button.
This seems to make it work initially. Basically the result being thrown back to me is the id value;
<input type="text" id="firstName" name="user_firstName"> <-- this is the console.log result for the field.
I've changed the code to remove all the nonsense to see if I can get the simplest form to work. Here is what I have.
var myFirstName = document.getElementById("firstName");
console.log(myFirstName);
W3C recommends this method -
function myFunction() { var x = document.getElementById("firstName"); var text = ""; var i; for (i = 0; i < x.length ;i++) { text += x.elements[i].value + "<br>"; } document.getElementById("demo").innerHTML = text;
but that doesn't work for me as it seems to target the entire form rather than each element.
Marcus Parsons
15,719 PointsUnfortunately, that doesn't really help, because we still aren't seeing the entire picture. I need to see the full code. If you're working with this code in Workspaces, post the URL for a snapshot of Workspaces. You can click the snapshot button in the top right corner of Workspaces. Then copy and paste the URL given from snapshots here.
Mark VonGyer
21,239 PointsMark VonGyer
21,239 Pointsto add to my question. How would I invoke a javascript function from the HTML element, whilst the function is located within my .js file.