tags:

views:

28

answers:

2

How to get the type of input in the form by its name? for example:

<input type="text" value="123" name="username" />

the return type should be "text".

Any ideas?

+3  A: 
<input type="text" value="123" name="username" id="username" />

getInputType("#username");

getInputType("input[name=username]");


function getInputType(selector){ 
  var inputType = $(selector).attr('type');
  alert(inputType);
  return inputType;
}
gmcalab
is it possible without the id?
Trez
yes i just made the change to show you how. notice the selector changed in the call to the method
gmcalab
+1  A: 
>>> document.getElementsByName("username")[0].type
"text"
voyager
That's not even a jQuery answer.
gmcalab
So?`​​​​​​​​​​​​`
voyager
Well, the request was for a jQuery solution.
gmcalab