It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming HTML Forum

Input tag without a name attribute?

Input tag without a name attribute?

Postby xximranxx on Mon Oct 06, 2008 12:58 pm

Hi.

Is it possible to have an input tag without a name attribute?

I found a form on www.swiss.com (Swiss Airlines), where the Return Date input tag (type="text") does not have a name tag.

Code: Select all
<label for='arrive'>Return</label>            <input id='inbound' maxlength='10' type='text' class='text' value='tt.mm.yyyy' onkeydown='runToggleDIVCalendar(false, this);checkDateInput(this,event);' onfocus='runToggleDIVCalendar(true, this);' onblur='formatDateFormat(this);' />


But I always thought that input tags must have a name tag.

P.S.: I am trying to automatically search for a certain flight on that site and need the name of the input tag fill the form automatically.


Can anybody help me understand?


Many Thanks,
Imran
xximranxx
 
Posts: 2
Joined: Mon Oct 06, 2008 12:50 pm

Postby rangana on Tue Oct 07, 2008 2:05 am

name is a deprecated attribute as far as XHTML is concern, and no, it's not mandatory if you intend to use it for HTML.

There are ways to fill a text box, some of these are:
1. via the standard, id attribute, using DOM getElementById();

2. via getting all the input elements, and knowing its index: document.getElementsByTagName('input')[indexHERE];

It is optional. For further reading:
http://www.w3schools.com/TAGS/tag_input.asp

Hope that makes sense.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby xximranxx on Tue Oct 07, 2008 11:21 am

I see. Thanks for the info. I will try out the get by id or get by index method.

The link that you included (to w3school.com) says (where explaing the 'name' attribute) that it is required for type 'text' and other types But not for all types (e.g. submit).

But I believe you if you say it is not required. As obviously the website works without the attribute.


Cheers,
imran
xximranxx
 
Posts: 2
Joined: Mon Oct 06, 2008 12:50 pm

Re: Input tag without a name attribute?

Postby rhyaniwyn on Wed Dec 30, 2009 9:26 pm

Wait, wait, wait. I have to necro.

If you take a gander at the W3 XHTML Specifications the HTML name attribute is deprecated for the elements a, applet, form, frame, iframe, img, and map for XHTML 1. The id attribute is now used in place of the name attribute as a unique identifying token in XHTML documents.

But the name attribute is NOT deprecated for input or select. Generally speaking, the deprecation of name does not affect the use of name for any fields in XHTML forms; in fact, name is essential to forms.

  • The name element is the one used to pass the values of form fields. If a field is not named using name, the field and its value will not be passed for server-side processing in most browsers. You COULD use javascript to loop through IDs and set the name to the id with javascript and associate the field value, but why would you want to do that when the deprecation of name does not at all affect any elements used XHTML forms aside from the form element itself?
  • Some form fields need to contain a matching name in order to function as expected. An input with the type "radio" is expected to present an array of options from which only one option can be chosen (otherwise you would use "checkbox"). This relationship between one radio and another is indicated by matching name attributes.

For more, see Using the name and id attributes in XHTML forms.
User avatar
rhyaniwyn
 
Posts: 1
Joined: Wed Dec 30, 2009 9:16 pm
Location: Florida


Who is online

Users browsing this forum: No registered users and 8 guests