View Full Version : How to assign ID to <input> text field and retrieve via JavaScript?

13 Sep 2010, 11:09 AM
Hello, I'want to do something like this to create a login form and retrieve the username/password:

var loginPanel = new Ext.Panel({
id: 'login-window',
xtype: 'fieldset',
cls: 'fieldset-login',
title: 'Welcome. Please log in to continue.',
items: [{
id: 'textfield-username',
xtype: 'textfield',
placeholder: 'User ID'
}, {
id: 'textfield-password',
xtype: 'passwordfield',
placeholder: 'Password'
}, {
xtype: 'button',
cls: 'button-login',
handler: ...,
text: 'Log In',
var username = Ext.cmp('textfield-username');
var password = Ext.cmp('textfield-password');

The problem is that even though I'm specifing an "id" property for the username and password text fields, the id actually gets applied to the parent <div> nodes--*not* the <input> element.

Can anyone suggest how I can get the id to apply to the input field itself, which would make it much easier for me to retrieve the username password (e.g., var username = Ext.cmp('textfield-username); )?


13 Sep 2010, 2:37 PM
Use getValue on the component, you don't need to access the field directly.