-1

How would i pull the user field info from the fields and store in a variable? I need it to then output that information into a div, its for an employee records database kind of thing.

    <!DOCTYPE html>
<html>
<head>
    <title>52DA session 5</title>
    <meta charset="utf-8" />
    <link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../css/employee_styles.css"/>
</head>
<body>
    <div id="container">
        <header>
            <h1 id="heading" class="blueTxt">Employee Records</h1>
        </header>
        <div class="left">
        <form>
            <fieldset>
                <legend><h2>Employee Details Entry</h2></legend>            
                <p class=><label>Name: <input class="text" type="text" id="name" /></label></p>
                <p><label>Age: <input class="text" type="text" id="age" /></label></p>
                <p><label>Position: <input class="text" type="text" id="position" /></label></p>
                <p><label>Details: <textarea type="text" id="details" maxlength="114" ></textarea></label></p>              
                <input class="button" type="button" id="addRecord" onclick="" value="Add Record"/>
            </fieldset>
        </form>             

            <div class="sort">
                <h3>Sort</h3>
                <button class="button" id="sortByName">By Name</button>
                <button class="button" id="sortByAge">By Age</button>
                <br/><button class="button" id="reset">Reset Details</button>
                <br /><br />
            </div>
        </div>
        <section>
            <div id="employeeRecords">

            </div>
        </section>

    </div>  

    <script src="../js/employee_script.js"></script>
</body>
</html>

heres my empty js

var employees = [];



//--------------------------------------------------------------------------------------------------------------

function Person(name, age, pos, dtls, img){

    this.fullName = name;
    this.employeeAge = age;
    this.position = pos;
    this.details = dtls;

    this.avatarSrc = img;

        this.createProfile = function(){
        var profile = document.createElement("div");
        profile.className = "profileStyle";
        var avatar = document.createElement("img");
        avatar.src = this.avatarSrc;
        avatar.alt = this.fullName();
        profile.appendChild(avatar);
        var profileTxt = document.createElement("p");
        profileTxt.innerHTML = "<b>" + this.fullName() +
        "</b><br />" + this.age + 
        "</b><br />" + this.pos + 
        "</b><br />" + this.dtls;
        profile.appendChild(profileTxt);
        return profile;
        }

    employees.push(this);

please make it as simple as possible

cheers! any help will be appreciated! Im fairly new to js and coding in general.

Lachlan M
  • 45
  • 1
  • 7

2 Answers2

0

For getting values from HTML form fields from where you want to get value

var x = document.getElementById("myText").value;

and you can set it as where you want to set

document.getElementById("result").value = x;
Rao
  • 397
  • 1
  • 12
0

I agree with @Rao and you can read this post that talk about how to get input field...

How do I get the value of text input field using JavaScript?

You can read from mozilla site https://developer.mozilla.org/it/docs/Web/JavaScript/Guida

And w3schools...

https://www.w3schools.com/js/

Ferdinando
  • 964
  • 1
  • 12
  • 23