please check my JS form


Question is:

Create an HTML document that contains two forms. One form consists of a text
field, the other a text area. Name the forms and the input devices. Use Java-
Script to print out the names and values in the forms.

However my code gives undefined on the values - can someone please advise.


<head><title>Id and Name Attributes</title>



<form name="form1">

<input type="text" name="text1" value="value"/>


<form name="form2">

<input type="textarea" name="text2" value="value"/>


<script type="text/javascript">
document.writeln("The name of the first form is " +;
document.writeln("The name of the second form is " +;
document.writeln("The name of the first form is " + document.form1.value);
document.writeln("The name of the second form is " + document.form2.value);

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lalit ChandraCommented:
Try this

user_input = document.forms[0].text.value

where text is the name of the text field, textarea or hidden field. The value of this element gives the text
jecommeraAuthor Commented:

Thanks for this however I am trying to understand this behaviour.

i.e. why is it giving back undefined instead of the value?
Lalit ChandraCommented: will get the control reference only,and you are trying to get concatenate that with the string.You should use VALUE to extract the value of the html text box control.
Also, document.form is somewhat deprecated.
 it's better to use document.form[0] instead.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.