stefanbund / 311

Interactive Web Development
33 stars 46 forks source link

How to pass user input to an object? #17

Closed PatrickMinett closed 7 years ago

PatrickMinett commented 7 years ago

I tried:

function objectBuild(firstName,lastName,corps){

var x,y,z;

x = document.getElementById("genfirstname").value; y = document.getElementById("genlastname").value; z = document.getelementById("gencorps").value;

this.firstName = x;

this.lastName = y;

this.corps = z;

}

this did not work, so I then tried,

var commander = new objectBuild (x,y,z); // was hoping this would act like the example but with user info being pulled from the users input.

Finally I tried:

`

`
stefanbund commented 7 years ago

Just a comment on your first plan, when you run object build, you need to assign values to each parameter in the method signature, not through get Element by ID inside the function

From Stefan Bund

On Jan 15, 2017, at 1:14 PM, PatrickMinett notifications@github.com wrote:

I tried:

function objectBuild(firstName,lastName,corps){

var x,y,z;

x = document.getElementById("genfirstname").value; y = document.getElementById("genlastname").value; z = document.getelementById("gencorps").value;

this.firstName = x;

this.lastName = y;

this.corps = z;

}

this did not work, so I then tried,

var commander = new objectBuild (x,y,z); // was hoping this would act like the example but with user info being pulled from the users input.

Finally I tried:

button type="button" onclick="objectBuild(firstName,lastName,corps)">Submit Answer

any suggestion's I am at a bit of a lose.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.