PDA

View Full Version : Using Element on form input with no id attribute



thegonz14
3 Aug 2007, 10:38 PM
Hi,

Where I work we use some software that generates forms and the input fields only include the name attribute, not the id attribute - like the following:



<input style="width: 562px;" autocomplete="off" size="100" name="textbox1" type="text">

<input type="submit" name="Next" cstyle="width: 70px;" value="Next" alt="Next">


We don't have any say over the HTML generated - it's as is unfortunately so we have to live with it that way.

Using Ext code such as the following then...


Ext.get('textbox1');
Ext.get('Next');


...works in IE but not in Firefox - I realize this is because there is no id attribute attached to the inputs. The error you get in Firebug is


this.el has no properties

I have done a good deal of searching on the forums and the only thing I could find was to make sure to include the id attribute - which, again I can't do natively as I don't control the HTML output.

I know I can access the DOM node using typical js methods but is there a way to use Ext directly to access the node to return the element without a bunch of overhead like converting the form into an extended Ext type form?

Thanks in advance for any help.

-Tyler

evant
3 Aug 2007, 11:54 PM
You could use selectors:



var o = Ext.get(Ext.query('input[name=myName]')[0]);
//o is now an Ext element.

thegonz14
4 Aug 2007, 9:04 PM
thanks evant - that worked perfectly!