How do I get a text value from an input element?

J

jmDesktop

If I have this:

<input type="text" onchange="doIt(this);" />

How can I get the value of the textbox in doIt()?

I tried:

function doIt(o){
alert(' it is: " + o.Value);
}

But I get o is undefined.

I am trying to display what the user just typed in and wanted to do it
with the this keyword.

Thank you.
 
T

Thomas 'PointedEars' Lahn

jmDesktop said:
If I have this:

<input type="text" onchange="doIt(this);" />

How can I get the value of the textbox in doIt()?

I tried:

function doIt(o){
alert(' it is: " + o.Value);
}

But I get o is undefined.

o.Value is `undefined' because ECMAScript implementations are
case-sensitive. o.value should work.


PointedEars
 
J

Jeff North

On Mon, 30 Jun 2008 14:02:36 -0700 (PDT), in comp.lang.javascript
jmDesktop <[email protected]>
| If I have this:
|
| <input type="text" onchange="doIt(this);" />
|
| How can I get the value of the textbox in doIt()?
|
| I tried:
|
| function doIt(o){
| alert(' it is: " + o.Value);
| }
|
| But I get o is undefined.
|
| I am trying to display what the user just typed in and wanted to do it
| with the this keyword.
|
| Thank you.

The onchange event occurs when a control loses the input focus and its
value has been modified since gaining focus.

The onkeypress event occurs when a key is pressed and released over an
element.
The onkeydown event occurs when a key is pressed down over an element.
The onkeyup event occurs when a key is released over an element.
 
S

suhasdhoke

If I have this:

<input type="text" onchange="doIt(this);" />

How can I get the value of the textbox in doIt()?

I tried:

function doIt(o){
  alert(' it is: " + o.Value);

}

But I get o is undefined.

I am trying to display what the user just typed in and wanted to do it
with the this keyword.

Thank you.


The *Value* is not a valid attribute. It is *value*.
Try This.

function doIt(o){
alert(' it is: " + o.value);
}
 
T

Thomas 'PointedEars' Lahn

The *Value* is not a valid attribute. It is *value*.

Your case suggestion is of course correct, however:

`value' is _not_ the name of an attribute here, but of a *property*. It is
only called an attribute in the HTML source code (which the property
represents, and where case does not matter), and in the specification of
the interface that the DOM host object implements (where case does matter).

Please trim your quotes.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top