Solved

please check my JS form

Posted on 2012-03-20
3
344 Views
Last Modified: 2012-03-20
Hi,

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.

thanks


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


</head>


<body>

<form name="form1">

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

</form>

<form name="form2">

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


</form>

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


</script>
</body>
</html>
0
Comment
Question by:jecommera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37744953
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
0
 

Author Comment

by:jecommera
ID: 37744959
Hi,

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

i.e. why is it giving back undefined instead of the value?
0
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37744997
document.form1.name 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.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Table header must be on top 2 58
Need help with a stick header please 12 31
Jquery Calculation 3 43
Javascript Error 10 24
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question