|
| ||||||||||
| Tags: c program, form element, html, javascript |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to set the value of a form element using Javascript?
__________________ In the end, we will remember not the words of our enemies, but the silence of our friends. -Martin Luther King Jr. |
|
#2
| ||||
| ||||
| 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. |
|
#3
| |||
| |||
| 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'; Code: this.form.elements["element_name"].value = 'Value Demo'; |
|
#4
| ||||
| ||||
| 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> |
|
#5
| ||||
| ||||
| 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'; 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> |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |