0

How do you get all of the inputs of form on a page into an array while matching by input type(text|checkbox|radio)?

JavaScript:

Just plain js like this will give me ALL of the inputs

var inputs = document.getElementsByTagName( 'input' );

Now with jQuery:

I have jQuery loaded and I tried: as per docs (http://api.jquery.com/text-selector/)

$( "<input>" ).is( ":text" ); 
$( "<input>" ).is( "[type=text]" ); 

Console Error message:

TypeError: undefined is not a function
message: "undefined is not a function"
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: Error

Additional information:

The page I am trying to get text inputs on is in an iFrame and this whole interaction is running within a webkit.

  • My main page has jQuery loaded.
  • The iFrame page does not.

Need to get inputs on iFrame page with jQuery from my main page.

MrPizzaFace
  • 7,807
  • 15
  • 79
  • 123

3 Answers3

5

To select an input with jQuery you would do this

$("input")

No brackets needed.

To select all text inputs

$("input[type='text']")

With the change in the question caused by the edit, you can find the answer here: Selecting an element in iFrame jQuery

Community
  • 1
  • 1
Robbert
  • 6,481
  • 5
  • 35
  • 61
0

So the given answer is accurate but you can also do

$(':text")

that will give you the all the text input items, just a little more readable in my opinion. again the answer from @Robbert is accurate

workabyte
  • 3,496
  • 2
  • 27
  • 35
0

You select all inputs of type="text" using:

$(':text')

Inputs of type="checkbox" using:

$(':checkbox')

Inputs of type="radio" using:

$(':radio')

EDIT To cater for new iframe information

Which would, for inputs in an iframe, translate to, respectively:

$('iframe').contents().find( ':text' );
$('iframe').contents().find( ':checkbox' );
$('iframe').contents().find( ':radio' );
PeterKA
  • 24,158
  • 5
  • 26
  • 48