Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to set the value of a form element using Javascript?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-02-2010
Member
 
Join Date: Aug 2006
Posts: 122
How to set the value of a form element using Javascript?
  

Hi. I am new to this forum. Hope that I am posting at right place.!! I have recently started with the JavaScript. Before that I did C, C++ and little bit of Java. Since I am new I don't know much about the JavaScript. I want your help for setting the value of a form element using Javascript? Please help me as soon as possible..!! Since, I am new to this forum, please ignore my mistakes.

__________________
In the end, we will remember not the words of our enemies, but the silence of our friends.
-Martin Luther King Jr.
Reply With Quote
  #2  
Old 07-02-2010
Member
 
Join Date: Jul 2006
Posts: 442
Re: How to set the value of a form element using Javascript?

Before moving to the actual coding, since you are new, I would like you to suggest to know more about the form in JavaScript. The first and best hidden is the form property. Also you should know that the form property of an element is not declared by you, but the system generates for you. In simple words you can say that it is simply a pointer that points back to the form containing the element. In JavaScript, you need to refer to the form from within the elements object. The 'name' and 'value' are the two most important properties that you declare as attributes of the form elements. The name stores the name of the form field. And the value property contains the value you want to pass back from that form field.
__________________
"When they give you ruled paper, write the other way..." J.R.J.
Reply With Quote
  #3  
Old 07-02-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to set the value of a form element using Javascript?

Setting the value of a form element is very important for the form. Its the first step of it. For setting the value of a textarea element using Javascript, you should read the described instructions. You can use the following syntax for setting the value :
Code:
oFormObject.elements["element_name"].value = 'Value Demo';
Suppose that you are accessing the form object through any of the form's elements, then you can use the following syntax :
Code:
 this.form.elements["element_name"].value = 'Value Demo';
Reply With Quote
  #4  
Old 07-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,843
Re: How to set the value of a form element using Javascript?

I am given very simple sample of the code, so that you can understand exactly why the value of a form element are set and how. Just have a look at the following coding :
Code:
<form name="admission_form" action="#">

Full Name: <input type="text" size="30" maxlength="60" name="name" >
Address: <input type="text" size="30" maxlength="350" name="email" >
Admission: <textarea name="admission_form" rows="45" cols="130"></textarea>
<input type="button" name="submit" value="Submit Admission" onclick="showElements(this.form);" >

</form>
Reply With Quote
  #5  
Old 07-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: How to set the value of a form element using Javascript?

You will also have to use the oFormObject.elements for setting the value of a text input field element in a form. For using that, the following is the syntax :
Code:
oFormObject.elements["element_name"].value = 'Some Value';
For more proper understanding about the setting the value of a text input field element in a form, just go through the coding :
HTML Code:
<form name="register_complaint" action="#">

Full Name: <input type="text" size="30" maxlength="60" name="name" >
Address: <input type="text" size="30" maxlength="250" name="address" >
Admission: <textarea name="admission_form" rows="45" cols="130"></textarea>
Months as member: <input type="text" size="5" maxlength="5" name="membership_period" >

<input type="button" name="increase" value="+" onclick="monthModify(this.form.elements["membership_period"], 'incr');" >
<input type="button" name="decrease" value="-" onclick="monthModify(this.form.elements["membership_period"], 'decr');" >
<input type="button" name="submit" value="Submit Complaint" onclick="showElements(this.form);" >

</form>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to set the value of a form element using Javascript?"
Thread Thread Starter Forum Replies Last Post
javascript get element by class GlassFish Software Development 5 06-03-2010 08:05 PM
Php form with javascript Solaris Software Development 3 30-11-2009 01:22 PM
Code to scroll to javascript element. sizzla Software Development 2 04-07-2009 10:13 PM
JavaScript - How to create Element Xylina Software Development 3 04-06-2009 05:06 PM
How do I know the width of an element through javascript? Conner Software Development 3 06-04-2009 11:29 AM


All times are GMT +5.5. The time now is 07:04 PM.