Take the 2-minute tour ×

I am a newbie when it comes to javascript, I'm playing with different tutorials and trying to make my own simple things to get a better understanding of it all. Today's learning is all about passing parameters through a function. What I would like to do is have a user fill a form in, submit those answers to variables in javascript and then call a function via an onClick event which will then display all the data entered into the form.

Firstly I hope this makes sense and secondly I hope that its the correct use of javascript, Im just trying to get a better understanding of passing params to be honest.

Could anyone advise any resources or point me in the right direction on where to get started with this small project

share|improve this question
Thank you for all your answers, much appreciated –  Richlewis Sep 13 '12 at 8:49
add comment

4 Answers

up vote 2 down vote accepted

form elements are select, input, textarea.

On form, add a submit event handler which does the following

Using document.getElementsByTagName method, you can get a array of all such elements in the form.

All these elements have a value property which will return the current value in it. Using this, you can create a string will the current data when form is submitted.

share|improve this answer
add comment
var data = document.getElementById('id').value;

check this: js variables

share|improve this answer
add comment

In order to get values from textboxes/textarea/dropdown having unique ID, you can use


If the input is DIV/SPAN, use innerHTML

share|improve this answer
add comment

Simplest way:

var javascriptvar = document.getElementById('CONTROL_ID').value;
share|improve this answer
add comment

Your Answer


