Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:51:24+00:00 2026-05-27T05:51:24+00:00

want to make values of the oject’s dynamic (from user input) but I get

  • 0

want to make values of the oject’s dynamic (from user input) but I get “undefined”. The idea is to have 3 input fields and the user should input values in them which will fill up the alert message.

<script type="text/javascript">
function Family (fatherName, motherName, sisterName) {

    this.fatherName = fatherName;
    this.motherName = motherName;
    this.sisterName = sisterName;
    this.myFamily = function() {
        alert("My father's name is " + this.fatherName +", my mother's name is "+ this.motherName +" and my sister's name is " + this.sisterName +".");
    }

}

var Me = new Family(
    Family["fatherName"] = father,
    Family["motherName"] = mother,
    Family["sisterName"] = siter);

var father = document.getElementById("fatherId").value;
var mother = document.getElementById("motherId").value;
var sister = document.getElementById("sisterId").value;
</script>

<input type="text" id="fatherId" />
<input type="text" id="motherId" />
<input type="text" id="fatherId" />
<input type="submit" value="Send" onclick="Me.myFamily();"> 

Also I’m looking for a way how user can add or remove properties (values in them, too).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:51:25+00:00Added an answer on May 27, 2026 at 5:51 am

    Here is the working snippet of your example.

    <input type="text" id="fatherId" />
    <input type="text" id="motherId" />
    <input type="text" id="sisterId" />
    <input type="submit" value="Send" id="submit" />
    
    <script>
        function Family(fatherName, motherName, sisterName) {
    
          this.fatherName = fatherName;
          this.motherName = motherName;
          this.sisterName = sisterName;
    
          this.myFamily = function() {
              alert("My father's name is " + this.fatherName + 
                    ", my mother's name is " + this.motherName + 
                    " and my sister's name is " + this.sisterName + ".");
          };
    
        }
    
        document.getElementById("submit").onclick = function() {
            var father = document.getElementById("fatherId").value;
            var mother = document.getElementById("motherId").value;
            var sister = document.getElementById("sisterId").value;
    
            Me = new Family(father, mother, sister);
            Me.myFamily();
        }
    </script>
    

    All the mistakes are summarized very well by Brandon.

    *EDIT: (anser to your comment)

    Your code has two execution related problems.

    • <script> tags are executed immediately and therefore if you insert script before the <input> part then there are no input elements available for you to retrieve.
    • You want to retrieve values of the inputs, but those inputs contain data when user clicks on the submit and therefore must be read using .value() at the onclick time. If you try to read them outside the onclick part then they are accessed immediately during page load when the input fields are empty.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make an hibernate querycount on a table. I have to values,
I want to make one thread that puts values to a queue when it
i want to find values in array according to alphabate and want to make
I want to make a judge, if checkbox value = 2, selected. But now
I want to make a GUI have a slider, this slider's value will be
With my Application, i want to make sure if user enter no value in
I want to make a ComboBox where the user can type an integer value
I want to make a sorted datagridview input. The following code snippet doesn't quite
I have a TreeMap map = new TreeMap(); to store values from documents in
I have an array that gets its values from a text file. Each line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.