today i was asked how you can obtain or get the value of a field within a html form. i found two ways of getting the values from an html form, this is how i did it.

lets say i have an html field like this:

<input name="user_name" type="text" value="">

so to call it from a function, i can use this javascript code:

var user_name = form.user_name.value;

so when the user enters a value in the user_name field the value will be of that field; here is a simple example code i wrote so you can test run it and do it yourself. i believe the best way to learn it so actually do it yourself. so open your text editor like notepad and copy and paste the code and save it as javascript.html and open it with your browser and see it in action.

HTML CODE: javascript.html
<script type="text/javascript" charset="iso-8859-1">
function validate_form(form) {
var user_name = form.user_name.value;
window.alert('Hi '+user_name);

Enter your name and then hit submit
<form onsubmit="return validate_form(this);">
<input name="user_name" type="text" value="">
<input type="submit" value="Submit">

now if you are too lazy to try it yourself, here i will give you a demo below, another question i was asked, how can you get the value from a field by the field id? well, i created another guide like this one with steps by step to help you. Learn how to get field id value with javascript
Enter your name and then hit submit